Skip to content
Verified contractPartialMIT

CreatorFeeRegistry

Address0x6cdec7f49036ccf1bba940011040fa044cfe6d08
Balance

0 ETH

 

Transactions

7

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 999,999 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,075,263
Creation transaction
0xe976b8e9d1…1fddce4c46

src/fees/CreatorFeeRegistry.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

import { Ownable2Step, Ownable } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { ICreatorFeeRegistry } from "../interfaces/ICreatorFeeRegistry.sol";

/// @title CreatorFeeRegistry
/// @notice Which tokens have a creator fee, and who receives it (creator-fees v2).
///
/// @dev Populated ONLY by authorized registrar contracts, never by end users. A registrar's whole
///      surface is enable/disable + the payout address, set
///      once at deploy; it gets no ongoing rights (the rate is a FeeRouter setting, and recipient
///      changes go through the admin). Plain `Ownable2Step` (matching `QuoteAssetRegistry`), not a
///      proxy — it holds no funds and its shape is fixed.
///
///      `activeCreator` is the one call on the swap hot path: it returns `address(0)` for an
///      unregistered OR disabled token, so the FeeRouter branches on a single value. Quote assets are
///      never registered, so the common WETH/USDC swap never even lands in a non-zero branch.
contract CreatorFeeRegistry is ICreatorFeeRegistry, Ownable2Step {
    struct TokenConfig {
        address creator; // zero == not registered
        bool disabled; // admin per-token kill switch
    }

    mapping(address => TokenConfig) public tokens;
    mapping(address => bool) public isRegistrar;

    /**
     * @notice When true, any token may register ITSELF. When false, only a registrar may register it.
     *
     * @dev OFF BY DEFAULT, AND THE FLIP IS AN OWNER ACTION with no delay. Closed, only an authorized
     *      registrar may register a token. Open, registration is permissionless and needs no allowlist
     *      to maintain.
     *
     *      TURNING IT OFF AGAIN STOPS NEW REGISTRATIONS AND NOTHING ELSE. Every existing registration
     *      keeps accruing and stays claimable: the switch is read only by {registerSelf}, and by nothing
     *      on the accrual or claim paths.
     */
    bool public openRegistration;

    event TokenRegistered(address indexed token, address indexed creator, address indexed registrar);
    event CreatorSet(address indexed token, address indexed creator);
    /// @notice A creator moved their OWN payout address. Deliberately distinct from {CreatorSet}, which
    ///         the admin path emits: the two carry the same two values but mean different things, so an
    ///         indexer can tell an admin reassignment from a creator's own redirection.
    event CreatorSetBySelf(address indexed token, address indexed previousCreator, address indexed creator);
    event TokenDisabled(address indexed token, bool disabled);
    event RegistrarSet(address indexed registrar, bool allowed);
    /// @notice The open-registration switch moved. Off by default; the flip is an owner action.
    event OpenRegistrationSet(bool open);

    error ZeroAddress();
    error NotRegistrar();
    error AlreadyRegistered();
    error NotRegistered();
    error NotCreator();
    /// @dev {registerSelf} was called while the door is shut.
    error RegistrationClosed();

    constructor(address initialOwner) Ownable(initialOwner) { }

    // --- registrar path ---

    /// @inheritdoc ICreatorFeeRegistry
    function register(address token, address creator) external {
        if (!isRegistrar[msg.sender]) revert NotRegistrar();
        if (token == address(0) || creator == address(0)) revert ZeroAddress();
        if (tokens[token].creator != address(0)) revert AlreadyRegistered();
        tokens[token] = TokenConfig({ creator: creator, disabled: false });
        emit TokenRegistered(token, creator, msg.sender);
    }

    /**
     * @notice Register the CALLING TOKEN with its creator. Open only while {openRegistration} is true.
     *
     * @dev THE BINDING IS `msg.sender == token`, AND IT IS THE WHOLE DESIGN. On the open path the
     *      registration must come from the token itself, so that an entry can only ever be made against
     *      the caller's own address. A token can be its own `msg.sender` and nothing else can be, which
     *      is the only form of that binding the EVM gives for free: a `register(token, creator)` taking
     *      an arbitrary address would carry no such guarantee, and reading `token.creator()` would be
     *      only as good as whatever the token chooses to return.
     *
     *      ONE REGISTRATION PER TOKEN, EVER, MADE BY THE TOKEN. A token that already has a creator is
     *      refused here exactly as it is on the registrar path, and that includes a DISABLED token:
     *      disabled means the admin stopped future accrual on a token that still has a creator, so
     *      re-enabling and reassignment are the admin's and nobody may register over an existing entry.
     *
     *      ONE REGISTRATION PER ADDRESS is what is actually enforced. Any address may register itself
     *      while the door is open, including an EOA; a non-token address never reaches the router's
     *      `activeCreator` branch, so nothing accrues to it.
     *
     *      THE OPEN PATH DOES NOT READ {isRegistrar}. A registrar's own route keeps working through
     *      {register} in both states, and this one never consults the allowlist, so there is no list to
     *      maintain when the door is open.
     */
    function registerSelf(address creator) external {
        if (!openRegistration) revert RegistrationClosed();
        if (creator == address(0)) revert ZeroAddress();
        if (tokens[msg.sender].creator != address(0)) revert AlreadyRegistered();
        tokens[msg.sender] = TokenConfig({ creator: creator, disabled: false });
        // The registering address IS the token here, which is what the third field reports.
        emit TokenRegistered(msg.sender, creator, msg.sender);
    }

    /// @notice Open or close permissionless self-registration. Owner action.
    /// @dev Closing it stops NEW registrations only. Nothing already earned moves, and nothing already
    ///      registered stops accruing: this flag is read by {registerSelf} and by nothing else.
    function setOpenRegistration(bool open) external onlyOwner {
        openRegistration = open;
        emit OpenRegistrationSet(open);
    }

    // --- creator path (the creator's own payout address) ---

    /// @notice Redirect a token's creator fee to another address, called BY the current creator.
    ///         A creator can change their own payout address without going through an admin. The admin
    ///         route ({adminSetCreator}) stays for takeovers and lost keys.
    /// @dev GATED ON {creatorOf}, NOT `activeCreator`, and the difference is load-bearing. The ask
    ///      specified `activeCreator`, which returns zero for a DISABLED token — so on a disabled
    ///      token the creator could still `claim` their accrued balance (the vault gates on
    ///      {creatorOf} for exactly that reason) but could not redirect who receives it. That is the
    ///      same split this codebase already closed once: `setDisabled` stops FUTURE accrual and must
    ///      not reach money already earned, and "whose money is it?" is answered by {creatorOf}
    ///      alone. Gating on `activeCreator` would let the owner freeze a creator's ability to move
    ///      their own balance by flipping a switch that is documented as not touching it.
    ///
    ///      One step, matching {adminSetCreator} rather than an accept-handshake: the fee stream is
    ///      the creator's own, a mistake is recoverable by the admin route, and a two-step here would
    ///      strand the balance of anyone who set a recipient that cannot call back.
    ///
    ///      Like the admin path, this moves the UNCLAIMED balance with the address — the vault keys
    ///      accrual per token, not per recipient. Intended, and the reason it is the creator's call.
    function setCreator(address token, address creator) external {
        if (creator == address(0)) revert ZeroAddress();
        address current = tokens[token].creator;
        if (current == address(0)) revert NotRegistered();
        if (msg.sender != current) revert NotCreator();
        tokens[token].creator = creator;
        // Both, on purpose: `CreatorSet` so anything already watching the registry keeps working
        // unchanged, and {CreatorSetBySelf} so a takeover stays distinguishable from a self-redirect.
        emit CreatorSet(token, creator);
        emit CreatorSetBySelf(token, current, creator);
    }

    // --- admin path ---

    /// @notice Hard-set the creator for a token (community takeover, lost keys, redirection). Because
    ///         accrual is per token, a takeover also captures the unclaimed balance — intended.
    function adminSetCreator(address token, address creator) external onlyOwner {
        if (creator == address(0)) revert ZeroAddress();
        if (tokens[token].creator == address(0)) revert NotRegistered();
        tokens[token].creator = creator;
        emit CreatorSet(token, creator);
    }

    /// @notice Disable (or re-enable) a token's creator fee. A disabled token trades at the normal rate
    ///         and its `activeCreator` returns zero, so the FeeRouter skims nothing further.
    /// @dev This switch does exactly one thing: stop future accrual. It does not touch money already
    ///      earned. The vault gates `claim` on {creatorOf} rather than `activeCreator`, so a balance
    ///      accrued before the switch stays claimable while the token is disabled.
    function setDisabled(address token, bool disabled) external onlyOwner {
        if (tokens[token].creator == address(0)) revert NotRegistered();
        tokens[token].disabled = disabled;
        emit TokenDisabled(token, disabled);
    }

    /// @notice Add or remove a registrar.
    function setRegistrar(address registrar, bool allowed) external onlyOwner {
        if (registrar == address(0)) revert ZeroAddress();
        isRegistrar[registrar] = allowed;
        emit RegistrarSet(registrar, allowed);
    }

    // --- hot path ---

    /// @inheritdoc ICreatorFeeRegistry
    function activeCreator(address token) external view returns (address) {
        TokenConfig storage c = tokens[token];
        return c.disabled ? address(0) : c.creator;
    }

    /// @inheritdoc ICreatorFeeRegistry
    /// @dev Deliberately ignores `disabled` — see the interface. `activeCreator` answers "should the
    ///      router skim?", this answers "whose money is it?", and those stopped being the same question
    ///      the moment a disabled token still had a balance sitting in the vault.
    function creatorOf(address token) external view returns (address) {
        return tokens[token].creator;
    }
}

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

lib/openzeppelin-contracts/contracts/access/Ownable2Step.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.20;

import {Ownable} from "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * This extension of the {Ownable} contract includes a two-step mechanism to transfer
 * ownership, where the new owner must call {acceptOwnership} in order to replace the
 * old one. This can help prevent common mistakes, such as transfers of ownership to
 * incorrect accounts, or to contracts that are unable to interact with the
 * permission system.
 *
 * The initial owner is specified at deployment time in the constructor for `Ownable`. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

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

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

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     *
     * Setting `newOwner` to the zero address is allowed; this can be used to cancel an initiated ownership transfer.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        if (pendingOwner() != sender) {
            revert OwnableUnauthorizedAccount(sender);
        }
        _transferOwnership(sender);
    }
}

lib/openzeppelin-contracts/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;
    }
}

src/interfaces/ICreatorFeeRegistry.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;

/// @title ICreatorFeeRegistry
/// @notice Which tokens have a creator fee, and who the creator is. Populated only by authorized
///         registrar contracts, never by end users
///         (creator-fees v2).
interface ICreatorFeeRegistry {
    /// @notice The address the FeeRouter branches on: the current creator of `token`, or `address(0)`
    ///         when the token is unregistered or its fee is disabled. One SLOAD on the swap hot path.
    function activeCreator(address token) external view returns (address);

    /// @notice The current creator of `token` REGARDLESS of the disabled flag, or `address(0)` when the
    ///         token was never registered.
    /// @dev The claim-side counterpart to {activeCreator}, and the two must not be conflated. Disabling a
    ///      token is a statement about FUTURE accrual — it stops the FeeRouter skimming, which is what
    ///      {activeCreator} returning zero is for. It is not a statement about money already earned, and
    ///      gating `CreatorFeeVault.claim` on {activeCreator} made it one: a disabled token's creator lost
    ///      access to fees already collected, indefinitely, at the registry owner's discretion.
    ///      This is a policy call rather than a correctness one: earned is earned, and withholding money
    ///      already earned as leverage is not a posture this protocol takes. So the vault reads THIS, the
    ///      router reads {activeCreator}, and disabling does exactly one thing.
    function creatorOf(address token) external view returns (address);

    /// @notice Register `token` with `creator`. Registrar-only; sets the initial (and, per v2, only)
    ///         creator. Reverts on a zero creator or a re-register.
    function register(address token, address creator) external;

    /**
     * @notice Register the CALLING TOKEN with its creator, while open registration is on.
     * @dev ON THE INTERFACE BECAUSE THIS IS THE ONE A THIRD PARTY INTEGRATES AGAINST. `register` is
     *      for the registrar; this is the open path, and an integrator reading only this interface
     *      needs to be able to see it.
     * @param creator who receives the fee. The entry is keyed on `msg.sender`, so a token can only ever
     *        register itself.
     */
    function registerSelf(address creator) external;

    /// @notice True while any token may register itself. Off by default.
    function openRegistration() external view returns (bool);
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 999999,
    "details": {
      "yulDetails": {
        "optimizerSteps": "dhfoDgvulfnTUtnIf",
        "stackAllocation": true
      }
    },
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "solady/=lib/solady/src/",
    "forge-std/=lib/forge-std/src/",
    "@layerzerolabs/oapp-evm/=lib/LayerZero-v2/packages/layerzero-v2/evm/oapp/",
    "@layerzerolabs/lz-evm-protocol-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/protocol/",
    "@layerzerolabs/lz-evm-messagelib-v2/=lib/LayerZero-v2/packages/layerzero-v2/evm/messagelib/",
    "@layerzerolabs/oft-evm/=lib/devtools/packages/oft-evm/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.