pub(crate) fn is_farm_expired(  
    farm: &Farm,  
  deps: Deps,  
  env: &Env,  
  config: &Config,  
) -> Result<bool, ContractError> {  
    let epoch_response: EpochResponse = deps  
  .querier  
  // query preliminary_end_epoch + 1 because the farm is preliminary ending at that epoch, including it.  
  .query_wasm_smart(  
            config.epoch_manager_addr.to_string(),  
  &QueryMsg::Epoch {  
                id: farm.preliminary_end_epoch + 1u64,  
  },  
  )?;  
  
  let farm_ending_at = epoch_response.epoch.start_time;  
  
  Ok(  
        farm.farm_asset.amount.saturating_sub(farm.claimed_amount) == Uint128::zero()  
            || farm_ending_at.plus_seconds(config.farm_expiration_time) < env.block.time,  
  )  
}
fn compute_farm_emissions(  
    farm: &Farm,  
  start_from_epoch: &EpochId,  
  current_epoch_id: &EpochId,  
) -> Result<(HashMap<EpochId, Uint128>, EpochId), ContractError> {  
    let mut farm_emissions = HashMap::new();  
  
  let until_epoch = if farm.preliminary_end_epoch <= *current_epoch_id {  
        // the preliminary_end_epoch is not inclusive, so we subtract 1  
  farm.preliminary_end_epoch - 1u64  
  } else {  
        *current_epoch_id  
  };  
  
  for epoch in *start_from_epoch..=until_epoch {  
  farm_emissions.insert(epoch, farm.emission_rate);  
  }  
  
    Ok((farm_emissions, until_epoch))  
}
