{
    "Function": "_claim",
    "File": "contracts/contracts/RewardsDistributor.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "IVotingEscrow",
        "IVotingEscrow",
        "Math",
        "IVotingEscrow",
        "Math"
    ],
    "Internal Calls": [
        "_find_timestamp_user_epoch"
    ],
    "Library Calls": [
        "max",
        "min"
    ],
    "Low-Level Calls": [],
    "Code": "function _claim(uint _tokenId, address ve, uint _last_token_time) internal returns (uint) {\n        uint user_epoch = 0;\n        uint to_distribute = 0;\n\n        uint max_user_epoch = IVotingEscrow(ve).user_point_epoch(_tokenId);\n        uint _start_time = start_time;\n\n        if (max_user_epoch == 0) return 0;\n\n        uint week_cursor = time_cursor_of[_tokenId];\n        if (week_cursor == 0) {\n            user_epoch = _find_timestamp_user_epoch(ve, _tokenId, _start_time, max_user_epoch);\n        } else {\n            user_epoch = user_epoch_of[_tokenId];\n        }\n\n        if (user_epoch == 0) user_epoch = 1;\n\n        IVotingEscrow.Point memory user_point = IVotingEscrow(ve).user_point_history(_tokenId, user_epoch);\n\n        if (week_cursor == 0) week_cursor = (user_point.ts + WEEK - 1) / WEEK * WEEK;\n        if (week_cursor >= last_token_time) return 0;\n        if (week_cursor < _start_time) week_cursor = _start_time;\n\n        IVotingEscrow.Point memory old_user_point;\n\n        for (uint i = 0; i < 50; i++) {\n            if (week_cursor >= _last_token_time) break;\n\n            if (week_cursor >= user_point.ts && user_epoch <= max_user_epoch) {\n                user_epoch += 1;\n                old_user_point = user_point;\n                if (user_epoch > max_user_epoch) {\n                    user_point = IVotingEscrow.Point(0,0,0,0);\n                } else {\n                    user_point = IVotingEscrow(ve).user_point_history(_tokenId, user_epoch);\n                }\n            } else {\n                int128 dt = int128(int256(week_cursor - old_user_point.ts));\n                uint balance_of = Math.max(uint(int256(old_user_point.bias - dt * old_user_point.slope)), 0);\n                if (balance_of == 0 && user_epoch > max_user_epoch) break;\n                if (balance_of != 0) {\n                    to_distribute += balance_of * tokens_per_week[week_cursor] / ve_supply[week_cursor];\n                }\n                week_cursor += WEEK;\n            }\n        }\n\n        user_epoch = Math.min(max_user_epoch, user_epoch - 1);\n        user_epoch_of[_tokenId] = user_epoch;\n        time_cursor_of[_tokenId] = week_cursor;\n\n        emit Claimed(_tokenId, to_distribute, user_epoch, max_user_epoch);\n\n        return to_distribute;\n    }"
}