diff --git a/matching_engine/src/generator_lib/generator_store.rs b/matching_engine/src/generator_lib/generator_store.rs index 881a6a2..dc6f0d4 100644 --- a/matching_engine/src/generator_lib/generator_store.rs +++ b/matching_engine/src/generator_lib/generator_store.rs @@ -812,54 +812,6 @@ impl GeneratorStore { GeneratorQueryResult::new(generator_result) } - #[deprecated( - note = "filter_by_available_native_stake and filter_by_available_symbiotic_stake will be used. filter_by_available_stake will be removed" - )] - pub fn filter_by_available_stake( - &self, - generator_query: GeneratorQueryResult, - min_stake: Vec, // Now accepting a vector of AddressTokenPairs - ) -> GeneratorQueryResult { - let generator_array = generator_query.result(); - - // Use rayon's parallel iterator to process in parallel - let generator_result: Vec<&GeneratorInfoPerMarket> = generator_array - .into_par_iter() // Convert the array to a parallel iterator - .filter_map(|elem| { - // Try to get the generator from the store - if let Some(generator) = self.generators.get(&elem.address) { - let remaining_stake = generator - .total_native_stake - .clone() - .add(generator.total_symbiotic_stake.clone()) - .sub( - generator - .native_stake_locked - .clone() - .add(generator.symbiotic_stake_locked.clone()), - ); - - // Check if at least one of the AddressTokenPairs in min_stake meets the condition - let is_valid = min_stake - .iter() - .any(|min_stake_pair| remaining_stake.has_more_than_or_eq(min_stake_pair)); - - // If valid, retrieve the generator market and return it - if is_valid { - self.generator_markets.get(&(elem.address, elem.market_id)) - } else { - None // Otherwise, filter it out - } - } else { - None // If generator doesn't exist, filter it out - } - }) - .collect(); // Collect the results into a Vec - - GeneratorQueryResult::new(generator_result) - } - - #[allow(unused)] pub fn filter_by_available_native_stake( &self, generator_query: GeneratorQueryResult, @@ -898,7 +850,6 @@ impl GeneratorStore { GeneratorQueryResult::new(generator_result) } - #[allow(unused)] pub fn filter_by_available_symbiotic_stake( &self, generator_query: GeneratorQueryResult, diff --git a/matching_engine/src/jobs/parser.rs b/matching_engine/src/jobs/parser.rs index e71fcda..17d5ab2 100644 --- a/matching_engine/src/jobs/parser.rs +++ b/matching_engine/src/jobs/parser.rs @@ -398,6 +398,8 @@ impl LogParser { &self.shared_market_store, &self.shared_key_store, random_pending_ask.reward, + &self.shared_native_stake_store, + &self.shared_symbiotic_stake_store, ) .await; @@ -668,16 +670,22 @@ impl LogParser { &self, random_pending_ask: LocalAsk, generator_store: &Arc>, - market_store: &Arc>, + _: &Arc>, key_store: &Arc>, task_reward: U256, + native_staking_store: &Arc>, + symbiotic_staking_store: &Arc>, ) -> Vec { // Ensure Generator implements Clone let generator_store = generator_store.read().await; - let market_metadata_store = market_store.read().await; let key_store = key_store.read().await; - let slashing_penalty = - market_metadata_store.get_slashing_penalty_by_market_id(&random_pending_ask.market_id); + let native_staking_store = native_staking_store.read().await; + let symbiotic_staking_store = symbiotic_staking_store.read().await; + + let native_stake_requirements = native_staking_store.tokens_to_lock.to_address_token_pair(); + let symbiotic_stake_requirements = symbiotic_staking_store + .tokens_to_lock + .to_address_token_pair(); let idle_generators = { let generator_query = { @@ -691,8 +699,18 @@ impl LogParser { let generator_with_idle_compute = generator_store.filter_by_has_idle_compute(generator_query); + let generator_with_available_native_stake = generator_store + .filter_by_available_native_stake( + generator_with_idle_compute, + native_stake_requirements, + ); + let generator_with_available_stake = generator_store - .filter_by_available_stake(generator_with_idle_compute, slashing_penalty); + .filter_by_available_symbiotic_stake( + generator_with_available_native_stake, + symbiotic_stake_requirements, + ); + generator_store.filter_by_has_private_inputs_support( generator_with_available_stake, key_store, @@ -707,8 +725,16 @@ impl LogParser { let generator_with_idle_compute = generator_store.filter_by_has_idle_compute(generator_query); - generator_store - .filter_by_available_stake(generator_with_idle_compute, slashing_penalty) + let generator_with_available_native_stake = generator_store + .filter_by_available_native_stake( + generator_with_idle_compute, + native_stake_requirements, + ); + + generator_store.filter_by_available_symbiotic_stake( + generator_with_available_native_stake, + symbiotic_stake_requirements, + ) } };