{
    "Function": "_checkpoint_token",
    "File": "contracts/contracts/RewardsDistributor.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "IERC20"
    ],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "function _checkpoint_token() internal {\n        uint token_balance = IERC20(token).balanceOf(address(this));\n        uint to_distribute = token_balance - token_last_balance;\n        token_last_balance = token_balance;\n\n        uint t = last_token_time;\n        uint since_last = block.timestamp - t;\n        last_token_time = block.timestamp;\n        uint this_week = t / WEEK * WEEK;\n        uint next_week = 0;\n\n        for (uint i = 0; i < 20; i++) {\n            next_week = this_week + WEEK;\n            if (block.timestamp < next_week) {\n                if (since_last == 0 && block.timestamp == t) {\n                    tokens_per_week[this_week] += to_distribute;\n                } else {\n                    tokens_per_week[this_week] += to_distribute * (block.timestamp - t) / since_last;\n                }\n                break;\n            } else {\n                if (since_last == 0 && next_week == t) {\n                    tokens_per_week[this_week] += to_distribute;\n                } else {\n                    tokens_per_week[this_week] += to_distribute * (next_week - t) / since_last;\n                }\n            }\n            t = next_week;\n            this_week = next_week;\n        }\n        emit CheckpointToken(block.timestamp, to_distribute);\n    }"
}