RevenueToken

0x0707c69e56886d54d05344bfba1ed02a759de289

Verification
Verified
v0.8.26+commit.8a97fa7a
Type
Contract
8,754 bytes
ABI entries
67
24 read · 11 write
License
none

Contract information

Address
0x0707c69e56886d54d05344bfba1ed02a759de289
Chain
Robinhood Chain (4663)
Compiler
v0.8.26+commit.8a97fa7a
Optimization
Enabled
Creation tx
0x2c300c69ec…66d8719e5e

Token

Name
EverythingIsComputer
Symbol
EIC
Decimals
18
Holders
123

Read contract (24)

DEAD()address
DEFAULT_SHARE_SYNC_GAS_LIMIT()uint32
active()bool
allowance(address, address)uint256
balanceOf(address)uint256
bound()bool
decimals()uint8
excluded(address)bool
initialHolder()address
liquidityVenue(address)bool
liquidityVenueCount()uint256
name()string
owner()address
pendingShareBalance(address)uint256
shareCoordinator()address
shareSyncDirty(address)bool
shareSyncGasLimit()uint32
shareSyncNonce(address)uint256
stakingEscrow()address
symbol()string
syncDebtCount()uint256
syncEpoch()uint256
systemExcluded(address)bool
totalSupply()uint256

Events (10)

ActivatedApprovalExclusionConfiguredLiquidityVenueRegisteredOwnershipTransferredShareCoordinatorBoundShareReconciledShareSyncDeferredStakingEscrowRegisteredTransfer

ABI

[
  {
    "inputs": [
      {
        "internalType": "string",
        "name": "name_",
        "type": "string"
      },
      {
        "internalType": "string",
        "name": "symbol_",
        "type": "string"
      },
      {
        "internalType": "uint256",
        "name": "initialSupply_",
        "type": "uint256"
      },
      {
        "internalType": "address",
        "name": "initialHolder_",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "owner_",
        "type": "address"
      },
      {
        "internalType": "uint32",
        "name": "shareSyncGasLimit_",
        "type": "uint32"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "inputs": [],
    "name": "AlreadyActive",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "AlreadyBound",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "ConfigurationSealed",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "allowance",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "needed",
        "type": "uint256"
      }
    ],
    "name": "ERC20InsufficientAllowance",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "sender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "balance",
        "type": "uint256"
      },
      {
        "internalType": "uint256",
        "name": "needed",
        "type": "uint256"
      }
    ],
    "name": "ERC20InsufficientBalance",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "approver",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidApprover",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "receiver",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidReceiver",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "sender",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidSender",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      }
    ],
    "name": "ERC20InvalidSpender",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "peer",
        "type": "address"
      }
    ],
    "name": "InvalidPeer",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "NoLiquidityVenue",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "NotActive",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "caller",
        "type": "address"
      }
    ],
    "name": "OnlyShareCoordinator",
    "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": [
      {
        "internalType": "address",
        "name": "peer",
        "type": "address"
      }
    ],
    "name": "PeerNotReady",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "PeersNotBound",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "StakingEscrowAlreadyRegistered",
    "type": "error"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "SystemExclusionRequired",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "ZeroAddress",
    "type": "error"
  },
  {
    "inputs": [],
    "name": "ZeroSupply",
    "type": "error"
  },
  {
    "anonymous": false,
    "inputs": [],
    "name": "Activated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "Approval",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "bool",
        "name": "excluded",
        "type": "bool"
      }
    ],
    "name": "ExclusionConfigured",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "venue",
        "type": "address"
      }
    ],
    "name": "LiquidityVenueRegistered",
    "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": "shareCoordinator",
        "type": "address"
      }
    ],
    "name": "ShareCoordinatorBound",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "balance",
        "type": "uint256"
      },
      {
        "indexed": true,
        "internalType": "uint256",
        "name": "nonce",
        "type": "uint256"
      }
    ],
    "name": "ShareReconciled",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "desiredBalance",
        "type": "uint256"
      },
      {
        "indexed": true,
        "internalType": "uint256",
        "name": "nonce",
        "type": "uint256"
      }
    ],
    "name": "ShareSyncDeferred",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "escrow",
        "type": "address"
      }
    ],
    "name": "StakingEscrowRegistered",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      {
        "indexed": true,
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "indexed": true,
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "indexed": false,
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "Transfer",
    "type": "event"
  },
  {
    "inputs": [],
    "name": "DEAD",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "DEFAULT_SHARE_SYNC_GAS_LIMIT",
    "outputs": [
      {
        "internalType": "uint32",
        "name": "",
        "type": "uint32"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "activate",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "active",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "owner",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      }
    ],
    "name": "allowance",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "spender",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "approve",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "balanceOf",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "shareCoordinator_",
        "type": "address"
      }
    ],
    "name": "bindShareCoordinator",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "bound",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "decimals",
    "outputs": [
      {
        "internalType": "uint8",
        "name": "",
        "type": "uint8"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "excluded",
    "outputs": [
      {
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "initialHolder",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "liquidityVenue",
    "outputs": [
      {
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "liquidityVenueCount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "name",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "owner",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "pendingShareBalance",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "reconcile",
    "outputs": [
      {
        "internalType": "bool",
        "name": "success",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "venue",
        "type": "address"
      }
    ],
    "name": "registerLiquidityVenue",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "escrow",
        "type": "address"
      }
    ],
    "name": "registerStakingEscrow",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "renounceOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      },
      {
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "name": "setExcluded",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "shareCoordinator",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "shareSyncDirty",
    "outputs": [
      {
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "shareSyncGasLimit",
    "outputs": [
      {
        "internalType": "uint32",
        "name": "",
        "type": "uint32"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "shareSyncNonce",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "stakingEscrow",
    "outputs": [
      {
        "internalType": "address",
        "name": "",
        "type": "address"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "symbol",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "syncDebtCount",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "syncEpoch",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "account",
        "type": "address"
      }
    ],
    "name": "systemExcluded",
    "outputs": [
      {
        "internalType": "bool",
        "name": "value",
        "type": "bool"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [],
    "name": "totalSupply",
    "outputs": [
      {
        "internalType": "uint256",
        "name": "",
        "type": "uint256"
      }
    ],
    "stateMutability": "view",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "transfer",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "from",
        "type": "address"
      },
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      }
    ],
    "name": "transferFrom",
    "outputs": [
      {
        "internalType": "bool",
        "name": "",
        "type": "bool"
      }
    ],
    "stateMutability": "nonpayable",
    "type": "function"
  },
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "newOwner",
        "type": "address"
      }
    ],
    "name": "transferOwnership",
    "outputs": [],
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Source code

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

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

import { IShareCoordinator } from "./interfaces/IShareCoordinator.sol";

interface IRevenuePeer {
    function revenueToken() external view returns (address);

    function active() external view returns (bool);
}

/// @notice Fixed-supply revenue token with sealed configuration and fail-open share mirroring.
contract RevenueToken is ERC20, Ownable {
    uint32 public constant DEFAULT_SHARE_SYNC_GAS_LIMIT = 200_000;
    address public constant DEAD = 0x000000000000000000000000000000000000dEaD;

    error ZeroAddress();
    error ZeroSupply();
    error InvalidPeer(address peer);
    error AlreadyBound();
    error PeersNotBound();
    error AlreadyActive();
    error ConfigurationSealed();
    error NoLiquidityVenue();
    error PeerNotReady(address peer);
    error SystemExclusionRequired(address account);
    error OnlyShareCoordinator(address caller);
    error NotActive();
    error StakingEscrowAlreadyRegistered();

    event ShareCoordinatorBound(address indexed shareCoordinator);
    event LiquidityVenueRegistered(address indexed venue);
    event ExclusionConfigured(address indexed account, bool excluded);
    event Activated();
    event ShareSyncDeferred(address indexed account, uint256 desiredBalance, uint256 indexed nonce);
    event ShareReconciled(address indexed account, uint256 balance, uint256 indexed nonce);
    event StakingEscrowRegistered(address indexed escrow);

    uint32 public immutable shareSyncGasLimit;
    address public immutable initialHolder;

    address public shareCoordinator;
    address public stakingEscrow;
    bool public bound;
    bool public active;
    uint256 public liquidityVenueCount;
    uint256 public syncDebtCount;
    uint256 public syncEpoch;

    mapping(address account => bool value) public liquidityVenue;
    mapping(address account => bool value) public excluded;
    mapping(address account => bool value) public systemExcluded;
    mapping(address account => bool value) public shareSyncDirty;
    mapping(address account => uint256 value) public shareSyncNonce;
    mapping(address account => uint256 value) public pendingShareBalance;

    bool private inShareSync;

    constructor(
        string memory name_,
        string memory symbol_,
        uint256 initialSupply_,
        address initialHolder_,
        address owner_,
        uint32 shareSyncGasLimit_
    ) ERC20(name_, symbol_) Ownable(owner_) {
        if (initialHolder_ == address(0) || owner_ == address(0)) revert ZeroAddress();
        if (initialSupply_ == 0) revert ZeroSupply();

        shareSyncGasLimit =
            shareSyncGasLimit_ == 0 ? DEFAULT_SHARE_SYNC_GAS_LIMIT : shareSyncGasLimit_;
        initialHolder = initialHolder_;

        _setSystemExcluded(address(this), true);
        _setSystemExcluded(DEAD, true);
        _mint(initialHolder_, initialSupply_);
    }

    /// @notice Binds the share coordinator used for the lifetime of the token.
    function bindShareCoordinator(address shareCoordinator_) external onlyOwner {
        if (bound) revert AlreadyBound();
        _requirePeer(shareCoordinator_);

        shareCoordinator = shareCoordinator_;
        bound = true;
        _setSystemExcluded(shareCoordinator_, true);
        emit ShareCoordinatorBound(shareCoordinator_);
    }

    /// @notice Registers a liquidity venue before activation and permanently excludes it.
    function registerLiquidityVenue(address venue) external onlyOwner {
        if (active) revert ConfigurationSealed();
        _requirePeer(venue);
        if (!liquidityVenue[venue]) {
            liquidityVenue[venue] = true;
            ++liquidityVenueCount;
            _setSystemExcluded(venue, true);
            emit LiquidityVenueRegistered(venue);
        }
    }

    /// @notice Configures non-system exclusions before activation.
    function setExcluded(address account, bool value) external onlyOwner {
        if (active) revert ConfigurationSealed();
        if (account == address(0)) revert ZeroAddress();
        if (systemExcluded[account] && !value) revert SystemExclusionRequired(account);
        excluded[account] = value;
        emit ExclusionConfigured(account, value);
    }

    /// @notice Irreversibly seals configuration and enables transfers with share synchronization.
    function activate() external onlyOwner {
        if (active) revert AlreadyActive();
        if (!bound) revert PeersNotBound();
        if (liquidityVenueCount == 0) revert NoLiquidityVenue();
        _requireReadyPeer(shareCoordinator);

        active = true;
        emit Activated();

        uint256 nonce = _premark(initialHolder);
        if (nonce != 0) _syncMarked(initialHolder, nonce);
    }

    /// @notice Permanently excludes the one future staking escrow from dividend synchronization.
    /// @dev The escrow remains outside owner-configured exclusions because `excluded` stays false.
    function registerStakingEscrow(address escrow) external {
        if (msg.sender != shareCoordinator) revert OnlyShareCoordinator(msg.sender);
        if (!active) revert NotActive();
        if (stakingEscrow != address(0)) revert StakingEscrowAlreadyRegistered();
        if (escrow == address(0) || escrow == address(this) || escrow.code.length == 0) {
            revert InvalidPeer(escrow);
        }
        stakingEscrow = escrow;
        _setSystemExcluded(escrow, false);
        emit StakingEscrowRegistered(escrow);
    }

    /// @notice Permissionlessly repairs a failed coordinator share callback.
    function reconcile(address account) external returns (bool success) {
        if (!_isShareEligibleEndpoint(account)) return true;
        uint256 nonce = shareSyncNonce[account];
        if (!shareSyncDirty[account]) return true;
        pendingShareBalance[account] = balanceOf(account);
        success = _attemptShareSync(account, nonce);
        if (success) _clearDebt(account, nonce);
    }

    function _update(address from, address to, uint256 amount) internal override {
        if (!active || inShareSync || from == address(0) || to == address(0)) {
            super._update(from, to, amount);
            return;
        }

        uint256 fromNonce;
        uint256 toNonce;
        if (amount != 0) {
            ++syncEpoch;
            fromNonce = _premarkAtEpoch(from, syncEpoch);
            if (to != from) toNonce = _premarkAtEpoch(to, syncEpoch);
        }

        super._update(from, to, amount);

        if (fromNonce != 0) _syncMarked(from, fromNonce);
        if (toNonce != 0) _syncMarked(to, toNonce);
    }

    function _premark(address account) internal returns (uint256 nonce) {
        ++syncEpoch;
        return _premarkAtEpoch(account, syncEpoch);
    }

    function _premarkAtEpoch(address account, uint256 epoch) internal returns (uint256 nonce) {
        if (!_isShareEligibleEndpoint(account)) return 0;
        if (!shareSyncDirty[account]) {
            shareSyncDirty[account] = true;
            ++syncDebtCount;
        }
        shareSyncNonce[account] = epoch;
        return epoch;
    }

    function _syncMarked(address account, uint256 nonce) internal {
        uint256 desired = balanceOf(account);
        pendingShareBalance[account] = desired;
        if (_attemptShareSync(account, nonce)) {
            _clearDebt(account, nonce);
        } else {
            emit ShareSyncDeferred(account, desired, nonce);
        }
    }

    function _attemptShareSync(address account, uint256 nonce) internal returns (bool success) {
        if (!shareSyncDirty[account] || shareSyncNonce[account] != nonce) return false;
        bytes memory data = abi.encodeCall(IShareCoordinator.sync, (account));
        address coordinator_ = shareCoordinator;
        uint256 gasLimit = shareSyncGasLimit;
        inShareSync = true;
        assembly ("memory-safe") {
            success := call(gasLimit, coordinator_, 0, add(data, 0x20), mload(data), 0, 0)
        }
        inShareSync = false;
    }

    function _clearDebt(address account, uint256 nonce) internal {
        if (!shareSyncDirty[account] || shareSyncNonce[account] != nonce) return;
        uint256 authoritativeBalance = balanceOf(account);
        if (pendingShareBalance[account] != authoritativeBalance) {
            pendingShareBalance[account] = authoritativeBalance;
            emit ShareSyncDeferred(account, authoritativeBalance, nonce);
            return;
        }
        shareSyncDirty[account] = false;
        --syncDebtCount;
        emit ShareReconciled(account, authoritativeBalance, nonce);
    }

    function _isShareEligibleEndpoint(address account) internal view returns (bool) {
        return account != address(0) && !systemExcluded[account] && !excluded[account];
    }

    function _setSystemExcluded(address account, bool alsoExcluded) internal {
        systemExcluded[account] = true;
        if (alsoExcluded) {
            excluded[account] = true;
            emit ExclusionConfigured(account, true);
        }
    }

    function _requirePeer(address peer) internal view {
        if (peer == address(0) || peer == address(this) || peer.code.length == 0) {
            revert InvalidPeer(peer);
        }
    }

    function _requireReadyPeer(address peer) internal view {
        try IRevenuePeer(peer).revenueToken() returns (address configuredToken) {
            if (configuredToken != address(this)) revert PeerNotReady(peer);
        } catch {
            revert PeerNotReady(peer);
        }
        try IRevenuePeer(peer).active() returns (bool peerActive) {
            if (!peerActive) revert PeerNotReady(peer);
        } catch {
            revert PeerNotReady(peer);
        }
    }
}
Chain explorer2435msChain node88ms