{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/FeeSplitter.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol",
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract FeeSplitter is Ownable, ReentrancyGuard {\n    using SafeERC20 for IERC20;\n\n    /* ------------------------------ EVENTS ------------------------------ */\n\n    /// @dev Emitted when a payment is released\n    /// @param to The address receiving the payment\n    /// @param token The token transfered\n    /// @param amount The amount paid\n    event PaymentReleased(address to, address token, uint256 amount);\n\n    /// @dev Emitted when a payment is received\n    /// @param from The address sending the tokens\n    /// @param token The token received\n    /// @param amount The amount received\n    event PaymentReceived(address from, address token, uint256 amount);\n\n    /// @dev Emitted when the royalties weight is updated\n    /// @param weigth The new weigth\n    event RoyaltiesWeightUpdated(uint256 weigth);\n\n    /// @dev Emitted when a new shareholder is added\n    /// @param account The new shareholder account\n    /// @param weight The shareholder weigth\n    event ShareholdersAdded(address account, uint256 weight);\n\n    /// @dev Emitted when a shareholder weight is updated\n    /// @param account The shareholder address\n    /// @param weight The new weight\n    event ShareholderUpdated(address account, uint256 weight);\n\n    /// @dev Emitted when royalties are claim released\n    /// @param to The address claiming the royalties\n    /// @param token The token received\n    /// @param value The amount received\n    event RoyaltiesReceived(address to, address token, uint256 value);\n\n    /* ------------------------------ STRUCTS ------------------------------ */\n\n    /// @dev Represent a shareholder\n    /// @param account Shareholders address that can receive income\n    /// @param weight Determines share allocation\n    struct Shareholder {\n        address account;\n        uint96 weight;\n    }\n\n    /// @dev Registers shares and amount release for a specific token or ETH\n    struct TokenRecords {\n        uint256 totalShares;\n        uint256 totalReleased;\n        mapping(address => uint256) shares;\n        mapping(address => uint256) released;\n    }\n\n    /* ----------------------------- VARIABLES ----------------------------- */\n\n    address private constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n\n    /// @dev Map of tokens with the tokenRecords\n    mapping(address => TokenRecords) private tokenRecords;\n\n    /// @dev All the shareholders (array)\n    Shareholder[] private shareholders;\n\n    /// @dev Royalties part weights when applicable\n    uint256 public royaltiesWeight;\n\n    uint256 public totalWeights;\n\n    address public immutable weth;\n\n    /* ---------------------------- CONSTRUCTOR ---------------------------- */\n\n    constructor(\n        address[] memory _accounts,\n        uint96[] memory _weights,\n        uint256 _royaltiesWeight,\n        address _weth\n    ) {\n        require(_weth != address(0), \"FS: INVALID_ADDRESS\");\n        // Initial shareholders addresses and weights\n        setShareholders(_accounts, _weights);\n        setRoyaltiesWeight(_royaltiesWeight);\n        weth = _weth;\n    }\n\n    /// @dev Receive ether after a WETH withdraw call\n    receive() external payable {\n        require(msg.sender == weth, \"FS: ETH_SENDER_NOT_WETH\");\n    }\n\n    /* -------------------------- OWNER FUNCTIONS -------------------------- */\n\n    /// @notice Sets the weight assigned to the royalties part for the fee\n    /// @param _weight The new royalties weight\n    function setRoyaltiesWeight(uint256 _weight) public onlyOwner {\n        require(_weight != 0, \"FS: WEIGHT_ZERO\");\n        totalWeights = totalWeights + _weight - royaltiesWeight;\n        royaltiesWeight = _weight;\n        emit RoyaltiesWeightUpdated(_weight);\n    }\n\n    /// @notice Sets a new list of shareholders\n    /// @param _accounts Shareholders accounts list\n    /// @param _weights Weight for each shareholder. Determines part of the payment allocated to them\n    function setShareholders(address[] memory _accounts, uint96[] memory _weights) public onlyOwner {\n        delete shareholders;\n        uint256 accountsLength = _accounts.length;\n        require(accountsLength != 0 && accountsLength == _weights.length, \"FS: INPUTS_LENGTH_MUST_MATCH\");\n        totalWeights = royaltiesWeight;\n\n        for (uint256 i = 0; i < accountsLength; i++) {\n            _addShareholder(_accounts[i], _weights[i]);\n        }\n    }\n\n    /// @notice Updates weight for a shareholder\n    /// @param _accountIndex Account to change the weight of\n    /// @param _weight The new weight\n    function updateShareholder(uint256 _accountIndex, uint96 _weight) external onlyOwner {\n        require(_accountIndex < shareholders.length, \"FS: INVALID_ACCOUNT_INDEX\");\n        totalWeights = totalWeights + _weight - shareholders[_accountIndex].weight;\n        require(totalWeights != 0, \"FS: TOTAL_WEIGHTS_ZERO\");\n        shareholders[_accountIndex].weight = _weight;\n        emit ShareholderUpdated(shareholders[_accountIndex].account, _weight);\n    }\n\n    /* -------------------------- USERS FUNCTIONS -------------------------- */\n\n    /// @notice Release multiple tokens and handle ETH unwrapping\n    /// @param _tokens ERC20 tokens to release\n    function releaseTokens(IERC20[] calldata _tokens) external nonReentrant {\n        uint256 amount;\n        for (uint256 i = 0; i < _tokens.length; i++) {\n            amount = _releaseToken(_msgSender(), _tokens[i]);\n            if (address(_tokens[i]) == weth) {\n                IWETH(weth).withdraw(amount);\n                (bool success, ) = _msgSender().call{ value: amount }(\"\");\n                require(success, \"FS: ETH_TRANFER_ERROR\");\n            } else {\n                _tokens[i].safeTransfer(_msgSender(), amount);\n            }\n            emit PaymentReleased(_msgSender(), address(_tokens[i]), amount);\n        }\n    }\n\n    /// @notice Release multiple tokens without ETH unwrapping\n    /// @param _tokens ERC20 tokens to release\n    function releaseTokensNoETH(IERC20[] calldata _tokens) external nonReentrant {\n        uint256 amount;\n        for (uint256 i = 0; i < _tokens.length; i++) {\n            amount = _releaseToken(_msgSender(), _tokens[i]);\n            _tokens[i].safeTransfer(_msgSender(), amount);\n            emit PaymentReleased(_msgSender(), address(_tokens[i]), amount);\n        }\n    }\n\n    /// @notice Sends a fee to this contract for splitting, as an ERC20 token. No royalties are expected.\n    /// @param _token Currency for the fee as an ERC20 token\n    /// @param _amount Amount of token as fee to be claimed by this contract\n    function sendFees(IERC20 _token, uint256 _amount) external nonReentrant {\n        uint256 weights;\n        unchecked {\n            weights = totalWeights - royaltiesWeight;\n        }\n\n        uint256 balanceBeforeTransfer = _token.balanceOf(address(this));\n        _token.safeTransferFrom(_msgSender(), address(this), _amount);\n\n        _sendFees(_token, _token.balanceOf(address(this)) - balanceBeforeTransfer, weights);\n    }\n\n    /// @notice Sends a fee to this contract for splitting, as an ERC20 token\n    /// @param _royaltiesTarget The account that can claim royalties\n    /// @param _token Currency for the fee as an ERC20 token\n    /// @param _amount Amount of token as fee to be claimed by this contract\n    function sendFeesWithRoyalties(\n        address _royaltiesTarget,\n        IERC20 _token,\n        uint256 _amount\n    ) external nonReentrant {\n        require(_royaltiesTarget != address(0), \"FS: INVALID_ROYALTIES_TARGET\");\n\n        uint256 balanceBeforeTransfer = _token.balanceOf(address(this));\n        _token.safeTransferFrom(_msgSender(), address(this), _amount);\n        uint256 amountReceived = _token.balanceOf(address(this)) - balanceBeforeTransfer;\n\n        uint256 royaltiesAmount = _computeShareCount(amountReceived, royaltiesWeight, totalWeights);\n\n        _sendFees(_token, amountReceived, totalWeights);\n        _addShares(_royaltiesTarget, royaltiesAmount, address(_token));\n\n        emit RoyaltiesReceived(_royaltiesTarget, address(_token), royaltiesAmount);\n    }\n\n    /* ------------------------------- VIEWS ------------------------------- */\n\n    /// @notice Returns the amount due to an account. Call releaseToken to withdraw the amount.\n    /// @param _account Account address to check the amount due for\n    /// @param _token ERC20 payment token address (or ETH_ADDR)\n    /// @return The total amount due for the requested currency\n    function getAmountDue(address _account, IERC20 _token) public view returns (uint256) {\n        TokenRecords storage _tokenRecords = tokenRecords[address(_token)];\n        if (_tokenRecords.totalShares == 0) return 0;\n\n        uint256 totalReceived = _tokenRecords.totalReleased + _token.balanceOf(address(this));\n        return\n            (totalReceived * _tokenRecords.shares[_account]) /\n            _tokenRecords.totalShares -\n            _tokenRecords.released[_account];\n    }\n\n    /// @notice Getter for the total shares held by shareholders.\n    /// @param _token Payment token address\n    /// @return The total shares count\n    function totalShares(address _token) external view returns (uint256) {\n        return tokenRecords[_token].totalShares;\n    }\n\n    /// @notice Getter for the total amount of token already released.\n    /// @param _token Payment token address\n    /// @return The total amount release to shareholders\n    function totalReleased(address _token) external view returns (uint256) {\n        return tokenRecords[_token].totalReleased;\n    }\n\n    /// @notice Getter for the amount of shares held by an account.\n    /// @param _account Account the shares belong to\n    /// @param _token Payment token address\n    /// @return The shares owned by the account\n    function shares(address _account, address _token) external view returns (uint256) {\n        return tokenRecords[_token].shares[_account];\n    }\n\n    /// @notice Getter for the amount of Ether already released to a shareholders.\n    /// @param _account The target account for this request\n    /// @param _token Payment token address\n    /// @return The amount already released to this account\n    function released(address _account, address _token) external view returns (uint256) {\n        return tokenRecords[_token].released[_account];\n    }\n\n    /// @notice Finds a shareholder and return its index\n    /// @param _account Account to find\n    /// @return The shareholder index in the storage array\n    function findShareholder(address _account) external view returns (uint256) {\n        for (uint256 i = 0; i < shareholders.length; i++) {\n            if (shareholders[i].account == _account) return i;\n        }\n        revert(\"FS: SHAREHOLDER_NOT_FOUND\");\n    }\n\n    /* ------------------------- PRIVATE FUNCTIONS ------------------------- */\n\n    /// @notice Transfers a fee to this contract\n    /// @dev This method calculates the amount received, to support deflationary tokens\n    /// @param _token Currency for the fee\n    /// @param _amount Amount of token sent\n    /// @param _totalWeights Total weights to determine the share count to allocate\n    function _sendFees(\n        IERC20 _token,\n        uint256 _amount,\n        uint256 _totalWeights\n    ) private {\n        Shareholder[] memory shareholdersCache = shareholders;\n        for (uint256 i = 0; i < shareholdersCache.length; i++) {\n            _addShares(\n                shareholdersCache[i].account,\n                _computeShareCount(_amount, shareholdersCache[i].weight, _totalWeights),\n                address(_token)\n            );\n        }\n        emit PaymentReceived(_msgSender(), address(_token), _amount);\n    }\n\n    /// @dev Increase the shares of a shareholder\n    /// @param _account The shareholder address\n    /// @param _shares The shares of the holder\n    /// @param _token The updated token\n    function _addShares(\n        address _account,\n        uint256 _shares,\n        address _token\n    ) private {\n        TokenRecords storage _tokenRecords = tokenRecords[_token];\n        _tokenRecords.shares[_account] += _shares;\n        _tokenRecords.totalShares += _shares;\n    }\n\n    function _releaseToken(address _account, IERC20 _token) private returns (uint256) {\n        uint256 amountToRelease = getAmountDue(_account, _token);\n        require(amountToRelease != 0, \"FS: NO_PAYMENT_DUE\");\n\n        TokenRecords storage _tokenRecords = tokenRecords[address(_token)];\n        _tokenRecords.released[_account] += amountToRelease;\n        _tokenRecords.totalReleased += amountToRelease;\n\n        return amountToRelease;\n    }\n\n    function _addShareholder(address _account, uint96 _weight) private {\n        require(_weight != 0, \"FS: ZERO_WEIGHT\");\n        require(_account != address(0), \"FS: INVALID_ADDRESS\");\n        for (uint256 i = 0; i < shareholders.length; i++) {\n            require(shareholders[i].account != _account, \"FS: ALREADY_SHAREHOLDER\");\n        }\n\n        shareholders.push(Shareholder(_account, _weight));\n        totalWeights += _weight;\n        emit ShareholdersAdded(_account, _weight);\n    }\n\n    function _computeShareCount(\n        uint256 _amount,\n        uint256 _weight,\n        uint256 _totalWeights\n    ) private pure returns (uint256) {\n        return (_amount * _weight) / _totalWeights;\n    }\n}"
}