{
    "Function": "slitherConstructorConstantVariables",
    "File": "src/Splits.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "abstract contract Splits {\n    /// @notice Maximum number of splits receivers of a single user. Limits the cost of splitting.\n    uint256 internal constant _MAX_SPLITS_RECEIVERS = 200;\n    /// @notice The total splits weight of a user\n    uint32 internal constant _TOTAL_SPLITS_WEIGHT = 1_000_000;\n    /// @notice The total amount the contract can keep track of each asset.\n    // slither-disable-next-line unused-state\n    uint256 internal constant _MAX_TOTAL_SPLITS_BALANCE = type(uint128).max;\n    /// @notice The storage slot holding a single `SplitsStorage` structure.\n    bytes32 private immutable _splitsStorageSlot;\n\n    /// @notice Emitted when a user collects funds\n    /// @param userId The user ID\n    /// @param assetId The used asset ID\n    /// @param collected The collected amount\n    event Collected(uint256 indexed userId, uint256 indexed assetId, uint128 collected);\n\n    /// @notice Emitted when funds are split from a user to a receiver.\n    /// This is caused by the user collecting received funds.\n    /// @param userId The user ID\n    /// @param receiver The splits receiver user ID\n    /// @param assetId The used asset ID\n    /// @param amt The amount split to the receiver\n    event Split(\n        uint256 indexed userId, uint256 indexed receiver, uint256 indexed assetId, uint128 amt\n    );\n\n    /// @notice Emitted when funds are made collectable after splitting.\n    /// @param userId The user ID\n    /// @param assetId The used asset ID\n    /// @param amt The amount made collectable for the user on top of what was collectable before.\n    event Collectable(uint256 indexed userId, uint256 indexed assetId, uint128 amt);\n\n    /// @notice Emitted when funds are given from the user to the receiver.\n    /// @param userId The user ID\n    /// @param receiver The receiver user ID\n    /// @param assetId The used asset ID\n    /// @param amt The given amount\n    event Given(\n        uint256 indexed userId, uint256 indexed receiver, uint256 indexed assetId, uint128 amt\n    );\n\n    /// @notice Emitted when the user's splits are updated.\n    /// @param userId The user ID\n    /// @param receiversHash The splits receivers list hash\n    event SplitsSet(uint256 indexed userId, bytes32 indexed receiversHash);\n\n    /// @notice Emitted when a user is seen in a splits receivers list.\n    /// @param receiversHash The splits receivers list hash\n    /// @param userId The user ID.\n    /// @param weight The splits weight. Must never be zero.\n    /// The user will be getting `weight / _TOTAL_SPLITS_WEIGHT`\n    /// share of the funds collected by the splitting user.\n    event SplitsReceiverSeen(bytes32 indexed receiversHash, uint256 indexed userId, uint32 weight);\n\n    struct SplitsStorage {\n        /// @notice User splits states.\n        /// The key is the user ID.\n        mapping(uint256 => SplitsState) splitsStates;\n    }\n\n    struct SplitsState {\n        /// @notice The user's splits configuration hash, see `hashSplits`.\n        bytes32 splitsHash;\n        /// @notice The user's splits balance. The key is the asset ID.\n        mapping(uint256 => SplitsBalance) balances;\n    }\n\n    struct SplitsBalance {\n        /// @notice The not yet split balance, must be split before collecting by the user.\n        uint128 splittable;\n        /// @notice The already split balance, ready to be collected by the user.\n        uint128 collectable;\n    }\n\n    /// @param splitsStorageSlot The storage slot to holding a single `SplitsStorage` structure.\n    constructor(bytes32 splitsStorageSlot) {\n        _splitsStorageSlot = splitsStorageSlot;\n    }\n\n    function _addSplittable(uint256 userId, uint256 assetId, uint128 amt) internal {\n        _splitsStorage().splitsStates[userId].balances[assetId].splittable += amt;\n    }\n\n    /// @notice Returns user's received but not split yet funds.\n    /// @param userId The user ID\n    /// @param assetId The used asset ID.\n    /// @return amt The amount received but not split yet.\n    function _splittable(uint256 userId, uint256 assetId) internal view returns (uint128 amt) {\n        return _splitsStorage().splitsStates[userId].balances[assetId].splittable;\n    }\n\n    /// @notice Calculate the result of splitting an amount using the current splits configuration.\n    /// @param userId The user ID\n    /// @param currReceivers The list of the user's current splits receivers.\n    /// @param amount The amount being split.\n    /// @return collectableAmt The amount made collectable for the user\n    /// on top of what was collectable before.\n    /// @return splitAmt The amount split to the user's splits receivers\n    function _splitResult(uint256 userId, SplitsReceiver[] memory currReceivers, uint128 amount)\n        internal\n        view\n        returns (uint128 collectableAmt, uint128 splitAmt)\n    {\n        _assertCurrSplits(userId, currReceivers);\n        if (amount == 0) {\n            return (0, 0);\n        }\n        uint32 splitsWeight = 0;\n        for (uint256 i = 0; i < currReceivers.length; i++) {\n            splitsWeight += currReceivers[i].weight;\n        }\n        splitAmt = uint128((uint160(amount) * splitsWeight) / _TOTAL_SPLITS_WEIGHT);\n        collectableAmt = amount - splitAmt;\n    }\n\n    /// @notice Splits the user's splittable funds among receivers.\n    /// The entire splittable balance of the given asset is split.\n    /// All split funds are split using the current splits configuration.\n    /// @param userId The user ID\n    /// @param assetId The used asset ID\n    /// @param currReceivers The list of the user's current splits receivers.\n    /// @return collectableAmt The amount made collectable for the user\n    /// on top of what was collectable before.\n    /// @return splitAmt The amount split to the user's splits receivers\n    function _split(uint256 userId, uint256 assetId, SplitsReceiver[] memory currReceivers)\n        internal\n        returns (uint128 collectableAmt, uint128 splitAmt)\n    {\n        _assertCurrSplits(userId, currReceivers);\n        mapping(uint256 => SplitsState) storage splitsStates = _splitsStorage().splitsStates;\n        SplitsBalance storage balance = splitsStates[userId].balances[assetId];\n\n        collectableAmt = balance.splittable;\n        if (collectableAmt == 0) {\n            return (0, 0);\n        }\n\n        balance.splittable = 0;\n        uint32 splitsWeight = 0;\n        for (uint256 i = 0; i < currReceivers.length; i++) {\n            splitsWeight += currReceivers[i].weight;\n            uint128 currSplitAmt =\n                uint128((uint160(collectableAmt) * splitsWeight) / _TOTAL_SPLITS_WEIGHT - splitAmt);\n            splitAmt += currSplitAmt;\n            uint256 receiver = currReceivers[i].userId;\n            _addSplittable(receiver, assetId, currSplitAmt);\n            emit Split(userId, receiver, assetId, currSplitAmt);\n        }\n        collectableAmt -= splitAmt;\n        balance.collectable += collectableAmt;\n        emit Collectable(userId, assetId, collectableAmt);\n    }\n\n    /// @notice Returns user's received funds already split and ready to be collected.\n    /// @param userId The user ID\n    /// @param assetId The used asset ID.\n    /// @return amt The collectable amount.\n    function _collectable(uint256 userId, uint256 assetId) internal view returns (uint128 amt) {\n        return _splitsStorage().splitsStates[userId].balances[assetId].collectable;\n    }\n\n    /// @notice Collects user's received already split funds\n    /// and transfers them out of the drips hub contract to msg.sender.\n    /// @param userId The user ID\n    /// @param assetId The used asset ID\n    /// @return amt The collected amount\n    function _collect(uint256 userId, uint256 assetId) internal returns (uint128 amt) {\n        SplitsBalance storage balance = _splitsStorage().splitsStates[userId].balances[assetId];\n        amt = balance.collectable;\n        balance.collectable = 0;\n        emit Collected(userId, assetId, amt);\n    }\n\n    /// @notice Gives funds from the user to the receiver.\n    /// The receiver can split and collect them immediately.\n    /// Transfers the funds to be given from the user's wallet to the drips hub contract.\n    /// @param userId The user ID\n    /// @param receiver The receiver\n    /// @param assetId The used asset ID\n    /// @param amt The given amount\n    function _give(uint256 userId, uint256 receiver, uint256 assetId, uint128 amt) internal {\n        _addSplittable(receiver, assetId, amt);\n        emit Given(userId, receiver, assetId, amt);\n    }\n\n    /// @notice Sets user splits configuration. The configuration is common for all assets.\n    /// Nothing happens to the currently splittable funds, but when they are split\n    /// after this function finishes, the new splits configuration will be used.\n    /// @param userId The user ID\n    /// @param receivers The list of the user's splits receivers to be set.\n    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.\n    /// Each splits receiver will be getting `weight / _TOTAL_SPLITS_WEIGHT`\n    /// share of the funds collected by the user.\n    function _setSplits(uint256 userId, SplitsReceiver[] memory receivers) internal {\n        SplitsState storage state = _splitsStorage().splitsStates[userId];\n        bytes32 newSplitsHash = _hashSplits(receivers);\n        emit SplitsSet(userId, newSplitsHash);\n        if (newSplitsHash != state.splitsHash) {\n            _assertSplitsValid(receivers, newSplitsHash);\n            state.splitsHash = newSplitsHash;\n        }\n    }\n\n    /// @notice Validates a list of splits receivers and emits events for them\n    /// @param receivers The list of splits receivers\n    /// @param receiversHash The hash of the list of splits receivers.\n    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.\n    function _assertSplitsValid(SplitsReceiver[] memory receivers, bytes32 receiversHash) private {\n        require(receivers.length <= _MAX_SPLITS_RECEIVERS, \"Too many splits receivers\");\n        uint64 totalWeight = 0;\n        // slither-disable-next-line uninitialized-local\n        uint256 prevUserId;\n        for (uint256 i = 0; i < receivers.length; i++) {\n            SplitsReceiver memory receiver = receivers[i];\n            uint32 weight = receiver.weight;\n            require(weight != 0, \"Splits receiver weight is zero\");\n            totalWeight += weight;\n            uint256 userId = receiver.userId;\n            if (i > 0) {\n                require(prevUserId != userId, \"Duplicate splits receivers\");\n                require(prevUserId < userId, \"Splits receivers not sorted by user ID\");\n            }\n            prevUserId = userId;\n            emit SplitsReceiverSeen(receiversHash, userId, weight);\n        }\n        require(totalWeight <= _TOTAL_SPLITS_WEIGHT, \"Splits weights sum too high\");\n    }\n\n    /// @notice Asserts that the list of splits receivers is the user's currently used one.\n    /// @param userId The user ID\n    /// @param currReceivers The list of the user's current splits receivers.\n    function _assertCurrSplits(uint256 userId, SplitsReceiver[] memory currReceivers)\n        internal\n        view\n    {\n        require(\n            _hashSplits(currReceivers) == _splitsHash(userId), \"Invalid current splits receivers\"\n        );\n    }\n\n    /// @notice Current user's splits hash, see `hashSplits`.\n    /// @param userId The user ID\n    /// @return currSplitsHash The current user's splits hash\n    function _splitsHash(uint256 userId) internal view returns (bytes32 currSplitsHash) {\n        return _splitsStorage().splitsStates[userId].splitsHash;\n    }\n\n    /// @notice Calculates the hash of the list of splits receivers.\n    /// @param receivers The list of the splits receivers.\n    /// Must be sorted by the splits receivers' addresses, deduplicated and without 0 weights.\n    /// @return receiversHash The hash of the list of splits receivers.\n    function _hashSplits(SplitsReceiver[] memory receivers)\n        internal\n        pure\n        returns (bytes32 receiversHash)\n    {\n        if (receivers.length == 0) {\n            return bytes32(0);\n        }\n        return keccak256(abi.encode(receivers));\n    }\n\n    /// @notice Returns the Splits storage.\n    /// @return splitsStorage The storage.\n    function _splitsStorage() private view returns (SplitsStorage storage splitsStorage) {\n        bytes32 slot = _splitsStorageSlot;\n        // slither-disable-next-line assembly\n        assembly {\n            splitsStorage.slot := slot\n        }\n    }\n}"
}