{
    "Function": "_updateReceiverStates",
    "File": "src/Drips.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "DripsConfigImpl",
        "DripsConfigImpl",
        "DripsConfigImpl",
        "DripsConfigImpl",
        "DripsConfigImpl"
    ],
    "Internal Calls": [
        "_currTimestamp",
        "_addDeltaRange",
        "_dripsRangeInFuture",
        "_dripsRangeInFuture",
        "_currTimestamp",
        "_isOrdered",
        "_cycleOf",
        "_addDeltaRange",
        "_addDeltaRange",
        "_cycleOf",
        "_dripsRangeInFuture",
        "_dripsRangeInFuture",
        "_cycleOf",
        "_addDeltaRange"
    ],
    "Library Calls": [
        "amtPerSec",
        "amtPerSec",
        "amtPerSec",
        "amtPerSec",
        "amtPerSec"
    ],
    "Low-Level Calls": [],
    "Code": "function _updateReceiverStates(\n        mapping(uint256 => DripsState) storage states,\n        DripsReceiver[] memory currReceivers,\n        uint32 lastUpdate,\n        uint32 currMaxEnd,\n        DripsReceiver[] memory newReceivers,\n        uint32 newMaxEnd\n    ) private {\n        uint256 currIdx = 0;\n        uint256 newIdx = 0;\n        while (true) {\n            bool pickCurr = currIdx < currReceivers.length;\n            // slither-disable-next-line uninitialized-local\n            DripsReceiver memory currRecv;\n            if (pickCurr) {\n                currRecv = currReceivers[currIdx];\n            }\n\n            bool pickNew = newIdx < newReceivers.length;\n            // slither-disable-next-line uninitialized-local\n            DripsReceiver memory newRecv;\n            if (pickNew) {\n                newRecv = newReceivers[newIdx];\n            }\n\n            // Limit picking both curr and new to situations when they differ only by time\n            if (\n                pickCurr && pickNew\n                    && (\n                        currRecv.userId != newRecv.userId\n                            || currRecv.config.amtPerSec() != newRecv.config.amtPerSec()\n                    )\n            ) {\n                pickCurr = _isOrdered(currRecv, newRecv);\n                pickNew = !pickCurr;\n            }\n\n            if (pickCurr && pickNew) {\n                // Shift the existing drip to fulfil the new configuration\n                DripsState storage state = states[currRecv.userId];\n                (uint32 currStart, uint32 currEnd) =\n                    _dripsRangeInFuture(currRecv, lastUpdate, currMaxEnd);\n                (uint32 newStart, uint32 newEnd) =\n                    _dripsRangeInFuture(newRecv, _currTimestamp(), newMaxEnd);\n                {\n                    int256 amtPerSec = int256(uint256(currRecv.config.amtPerSec()));\n                    // Move the start and end times if updated\n                    _addDeltaRange(state, currStart, newStart, -amtPerSec);\n                    _addDeltaRange(state, currEnd, newEnd, amtPerSec);\n                }\n                // Ensure that the user receives the updated cycles\n                uint32 currStartCycle = _cycleOf(currStart);\n                uint32 newStartCycle = _cycleOf(newStart);\n                // The `currStartCycle > newStartCycle` check is just an optimization.\n                // If it's false, then `state.nextReceivableCycle > newStartCycle` must be\n                // false too, there's no need to pay for the storage access to check it.\n                // slither-disable-next-line timestamp\n                if (currStartCycle > newStartCycle && state.nextReceivableCycle > newStartCycle) {\n                    state.nextReceivableCycle = newStartCycle;\n                }\n            } else if (pickCurr) {\n                // Remove an existing drip\n                // slither-disable-next-line similar-names\n                DripsState storage state = states[currRecv.userId];\n                (uint32 start, uint32 end) = _dripsRangeInFuture(currRecv, lastUpdate, currMaxEnd);\n                // slither-disable-next-line similar-names\n                int256 amtPerSec = int256(uint256(currRecv.config.amtPerSec()));\n                _addDeltaRange(state, start, end, -amtPerSec);\n            } else if (pickNew) {\n                // Create a new drip\n                DripsState storage state = states[newRecv.userId];\n                // slither-disable-next-line uninitialized-local\n                (uint32 start, uint32 end) =\n                    _dripsRangeInFuture(newRecv, _currTimestamp(), newMaxEnd);\n                int256 amtPerSec = int256(uint256(newRecv.config.amtPerSec()));\n                _addDeltaRange(state, start, end, amtPerSec);\n                // Ensure that the user receives the updated cycles\n                uint32 startCycle = _cycleOf(start);\n                // slither-disable-next-line timestamp\n                if (state.nextReceivableCycle == 0 || state.nextReceivableCycle > startCycle) {\n                    state.nextReceivableCycle = startCycle;\n                }\n            } else {\n                break;\n            }\n\n            if (pickCurr) {\n                currIdx++;\n            }\n            if (pickNew) {\n                newIdx++;\n            }\n        }\n    }"
}