//contracts/farm-manager/src/farm/commands.rs
pub(crate) fn calculate_rewards(
...
) -> Result<RewardsResponse, ContractError> {
...
        for epoch_id in start_from_epoch..=until_epoch {
...
            let user_weight = user_weights[&epoch_id];
            let total_lp_weight = contract_weights
                .get(&epoch_id)
                .unwrap_or(&Uint128::zero())
                .to_owned();
            //@audit contract_weights or total_lp_weight can be zero, when used as a fraction with checked_mul_floor, this causes division by zero error.
|>          let user_share = (user_weight, total_lp_weight);

            let reward = farm_emissions
                .get(&epoch_id)
                .unwrap_or(&Uint128::zero())
                .to_owned()
|>              .checked_mul_floor(user_share)?;
...
//contracts/farm-manager/src/position/helpers.rs
pub fn reconcile_user_state(
    deps: DepsMut,
    receiver: &Addr,
    position: &Position,
) -> Result<(), ContractError> {
    let receiver_open_positions = get_positions_by_receiver(
        deps.storage,
        receiver.as_ref(),
        Some(true),
        None,
        Some(MAX_ITEMS_LIMIT),
    )?;

    // if the user has no more open positions, clear the last claimed epoch
    //@audit-info note: LAST_CLAIMED_EPOCH will not be cleared for the user when the user has open positions in other lp_denom
    if receiver_open_positions.is_empty() {
|>      LAST_CLAIMED_EPOCH.remove(deps.storage, receiver);
    }
...
running 1 test
test test_query_rewards_divide_by_zero_cause_rewards_locked ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 40 filtered out; finished in 0.01s
