{
    "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    address private constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\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 released\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 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        uint256 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    /// @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        address[] memory _accounts,\n        uint256[] memory _weights,\n        uint256 _royaltiesWeight,\n        address _weth\n    ) {\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(_msgSender() == weth, \"FeeSplitter: ETH_SENDER_NOT_WETH\");\n    }\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        uint256 totalReceived = _tokenRecords.totalReleased;\n        if (_tokenRecords.totalShares == 0) return 0;\n        else totalReceived += _token.balanceOf(address(this));\n        uint256 amountDue = (totalReceived * _tokenRecords.shares[_account]) /\n            _tokenRecords.totalShares -\n            _tokenRecords.released[_account];\n        return amountDue;\n    }\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        totalWeights -= royaltiesWeight;\n        royaltiesWeight = _weight;\n        totalWeights += _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, uint256[] memory _weights) public onlyOwner {\n        delete shareholders;\n        require(_accounts.length > 0 && _accounts.length == _weights.length, \"FeeSplitter: ARRAY_LENGTHS_ERR\");\n        totalWeights = royaltiesWeight;\n\n        for (uint256 i = 0; i < _accounts.length; i++) {\n            _addShareholder(_accounts[i], _weights[i]);\n        }\n    }\n\n    /// @notice Triggers a transfer to `msg.sender` of the amount of token they are owed, according to\n    /// the amount of shares they own and their previous withdrawals.\n    /// @param _token Payment token address\n    function releaseToken(IERC20 _token) public nonReentrant {\n        uint256 amount = _releaseToken(_msgSender(), _token);\n        _token.safeTransfer(_msgSender(), amount);\n        emit PaymentReleased(_msgSender(), address(_token), amount);\n    }\n\n    /// @notice Call releaseToken() for multiple tokens\n    /// @param _tokens ERC20 tokens to release\n    function releaseTokens(IERC20[] memory _tokens) external {\n        for (uint256 i = 0; i < _tokens.length; i++) {\n            releaseToken(_tokens[i]);\n        }\n    }\n\n    /// @dev Triggers a transfer to `msg.sender` of the amount of Ether they are owed, according to\n    /// the amount of shares they own and their previous withdrawals.\n    function releaseETH() external nonReentrant {\n        uint256 amount = _releaseToken(_msgSender(), IERC20(weth));\n        IWETH(weth).withdraw(amount);\n        (bool success, ) = _msgSender().call{ value: amount }(\"\");\n        require(success, \"FeeSplitter: ETH_TRANFER_ERROR\");\n        emit PaymentReleased(_msgSender(), ETH, amount);\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 = totalWeights - royaltiesWeight;\n        _sendFees(_token, _amount, 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), \"FeeSplitter: INVALID_ROYALTIES_TARGET_ADDRESS\");\n\n        _sendFees(_token, _amount, totalWeights);\n        _addShares(_royaltiesTarget, _computeShareCount(_amount, royaltiesWeight, totalWeights), address(_token));\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, uint256 _weight) external onlyOwner {\n        require(_accountIndex + 1 <= shareholders.length, \"FeeSplitter: INVALID_ACCOUNT_INDEX\");\n        uint256 _totalWeights = totalWeights;\n        _totalWeights -= shareholders[_accountIndex].weight;\n        shareholders[_accountIndex].weight = _weight;\n        _totalWeights += _weight;\n        require(_totalWeights > 0, \"FeeSplitter: TOTAL_WEIGHTS_ZERO\");\n        totalWeights = _totalWeights;\n    }\n\n    /// @notice Getter for the total shares held by shareholders.\n    /// @param _token Payment token address, use ETH_ADDR for ETH\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, use ETH_ADDR for ETH\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, use ETH_ADDR for ETH\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, use ETH_ADDR for ETH\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(\"FeeSplitter: NOT_FOUND\");\n    }\n\n    /// @dev Transfers a fee to this contract\n    /// @param _token Currency for the fee\n    /// @param _amount Amount of token as fee\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        IERC20(_token).safeTransferFrom(_msgSender(), address(this), _amount);\n\n        for (uint256 i = 0; i < shareholders.length; i++) {\n            _addShares(\n                shareholders[i].account,\n                _computeShareCount(_amount, shareholders[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 = _tokenRecords.totalShares + _shares;\n    }\n\n    function _releaseToken(address _account, IERC20 _token) private returns (uint256) {\n        TokenRecords storage _tokenRecords = tokenRecords[address(_token)];\n        uint256 amountToRelease = getAmountDue(_account, _token);\n        require(amountToRelease != 0, \"FeeSplitter: NO_PAYMENT_DUE\");\n\n        _tokenRecords.released[_account] = _tokenRecords.released[_account] + amountToRelease;\n        _tokenRecords.totalReleased = _tokenRecords.totalReleased + amountToRelease;\n\n        return amountToRelease;\n    }\n\n    function _addShareholder(address _account, uint256 _weight) private {\n        require(_weight > 0, \"FeeSplitter: ZERO_WEIGHT\");\n        shareholders.push(Shareholder(_account, _weight));\n        totalWeights += _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}"
}