```\n  function addToTotalRewards(uint256 _basketId) internal onlyBasketOwner(_basketId) {\n    if (baskets[_basketId].nrOfAllocatedTokens == 0) return;\n\n\n    uint256 vaultNum = baskets[_basketId].vaultNumber;\n    uint256 currentRebalancingPeriod = vaults[vaultNum].rebalancingPeriod;\n    uint256 lastRebalancingPeriod = baskets[_basketId].lastRebalancingPeriod;\n\n\n    if (currentRebalancingPeriod <= lastRebalancingPeriod) return;\n\n\n    for (uint k = 0; k < chainIds.length; k++) {\n      uint32 chain = chainIds[k];\n      uint256 latestProtocol = latestProtocolId[chain];\n      for (uint i = 0; i < latestProtocol; i++) {\n        int256 allocation = basketAllocationInProtocol(_basketId, chain, i) / 1E18;\n        if (allocation == 0) continue;\n\n\n        int256 lastRebalanceReward = getRewardsPerLockedToken(\n          vaultNum,\n          chain,\n          lastRebalancingPeriod,\n          i\n        );\n        int256 currentReward = getRewardsPerLockedToken(\n          vaultNum,\n          chain,\n          currentRebalancingPeriod,\n          i\n        );\n        baskets[_basketId].totalUnRedeemedRewards +=\n          (currentReward - lastRebalanceReward) *\n          allocation;\n      }\n    }\n  }\n```\n