From 081c4cb8087ba97d2a499a9961b0379fc7fc04e0 Mon Sep 17 00:00:00 2001 From: Akshay Date: Fri, 15 Nov 2024 14:10:03 +0000 Subject: [PATCH] listen staking manager events --- .../src/generator_lib/generator_store.rs | 2 +- matching_engine/src/jobs/parser.rs | 18 +++++++ matching_engine/src/lib.rs | 14 ++++++ .../src/log_processor/constants.rs | 1 + matching_engine/src/log_processor/mod.rs | 1 + matching_engine/src/log_processor/sm.rs | 49 +++++++++++++++++++ 6 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 matching_engine/src/log_processor/sm.rs diff --git a/matching_engine/src/generator_lib/generator_store.rs b/matching_engine/src/generator_lib/generator_store.rs index 8d013fc..bbbab9f 100644 --- a/matching_engine/src/generator_lib/generator_store.rs +++ b/matching_engine/src/generator_lib/generator_store.rs @@ -993,7 +993,7 @@ mod tests { pub static TEST_TOKEN_ADDRESS_TWO: Lazy
= Lazy::new(|| TEST_TOKEN_ADDRESS_TWO_STRING.parse::
().unwrap()); - + #[allow(unused)] pub static TEST_TOKEN_ADDRESS_THREE: Lazy
= Lazy::new(|| TEST_TOKEN_ADDRESS_THREE_STRING.parse::
().unwrap()); diff --git a/matching_engine/src/jobs/parser.rs b/matching_engine/src/jobs/parser.rs index 77ccd56..803713b 100644 --- a/matching_engine/src/jobs/parser.rs +++ b/matching_engine/src/jobs/parser.rs @@ -51,6 +51,9 @@ type SymbioticStakingInstance = bindings::symbiotic_staking::SymbioticStaking< type NativeStakingInstance = bindings::native_staking::NativeStaking, Wallet>>; +type StakingManagerInstance = + bindings::staking_manager::StakingManager, Wallet>>; + pub struct LogParser { should_stop: Arc, start_block: Arc>, @@ -61,6 +64,7 @@ pub struct LogParser { entity_registry: EntityRegistryInstance, symbiotic_staking: SymbioticStakingInstance, native_staking: NativeStakingInstance, + staking_manager: StakingManagerInstance, provider_http: Arc, Wallet>>, matching_engine_key: Vec, matching_engine_slave_keys: Vec>, @@ -90,6 +94,7 @@ impl LogParser { entity_registry: EntityRegistryInstance, symbiotic_staking: SymbioticStakingInstance, native_staking: NativeStakingInstance, + staking_manager: StakingManagerInstance, matching_engine_key: String, matching_engine_slave_keys: Vec, shared_local_ask_store: Arc>, @@ -116,6 +121,7 @@ impl LogParser { entity_registry, symbiotic_staking, native_staking, + staking_manager, provider_http, matching_engine_key: hex::decode(matching_engine_key).unwrap(), matching_engine_slave_keys: matching_engine_slave_keys @@ -173,6 +179,7 @@ impl LogParser { let entity_key_registry_address = self.entity_registry.address(); let native_staking_address = self.native_staking.address(); let symbiotic_staking_address = self.symbiotic_staking.address(); + let staking_manager_address = self.staking_manager.address(); let filter = Filter::default() .from_block(start_block) @@ -183,6 +190,7 @@ impl LogParser { entity_key_registry_address, native_staking_address, symbiotic_staking_address, + staking_manager_address, ]); let logs = match self.provider_http.get_logs(&filter).await { @@ -283,6 +291,16 @@ impl LogParser { continue; } + if log.address.eq(&staking_manager_address) { + log_processor::sm::process_staking_manager_log( + log, + &self.staking_manager, + ) + .await + .unwrap(); + continue; + } + log::error!("Log of unknown contract found {:?}", log.address); return Err(anyhow::anyhow!("Unknown log")); } diff --git a/matching_engine/src/lib.rs b/matching_engine/src/lib.rs index 8d7206e..96cce42 100644 --- a/matching_engine/src/lib.rs +++ b/matching_engine/src/lib.rs @@ -116,6 +116,8 @@ pub struct MatchingEngineConfig { pub symbiotic_staking: String, #[serde(default = "default_native_staking")] pub native_staking: String, + #[serde(default = "default_staking_manager")] + pub staking_manager: String, pub start_block: String, } @@ -129,6 +131,10 @@ fn default_native_staking() -> String { "0xe9d2Bcc597f943ddA9EDf356DAC7C6A713dDE113".to_string() } +fn default_staking_manager() -> String { + "0xCe75C0E25b2c70415b237273345105402aEbe79F".to_string() +} + pub struct MatchingEngine { config: MatchingEngineConfig, matching_engine_port: u16, @@ -153,6 +159,7 @@ impl MatchingEngine { entity_registry: String, symbiotic_staking: String, native_staking: String, + staking_manager: String, start_block: String, matching_engine_port: Option, ) -> Self { @@ -166,6 +173,7 @@ impl MatchingEngine { entity_registry, symbiotic_staking, native_staking, + staking_manager, start_block, }; @@ -269,6 +277,11 @@ impl MatchingEngine { let shared_native_staking = bindings::native_staking::NativeStaking::new(native_staking_address, client.clone()); + let staking_manager_var = self.config.clone().staking_manager; + let staking_manager_address = Address::from_str(&staking_manager_var).unwrap(); + let shared_staking_manager = + bindings::staking_manager::StakingManager::new(staking_manager_address, client.clone()); + let shared_parsed_block_number_store = Arc::new(RwLock::new( U64::from_dec_str(&start_block_string).expect("Unable to rad start_block"), )); @@ -333,6 +346,7 @@ impl MatchingEngine { entity_key_registry, shared_symbiotic_staking, shared_native_staking, + shared_staking_manager, matching_engine_key, vec![], //TODO! fetch these slave keys using Oyster KMS shared_local_ask_store.clone(), diff --git a/matching_engine/src/log_processor/constants.rs b/matching_engine/src/log_processor/constants.rs index aa0b61f..f2df41a 100644 --- a/matching_engine/src/log_processor/constants.rs +++ b/matching_engine/src/log_processor/constants.rs @@ -21,4 +21,5 @@ lazy_static! { pub static ref ENTITY_KEY_REGISTRY_TOPICS_SKIP: HashSet = TOPICS_TO_SKIP.clone(); pub static ref NATIVE_STAKING_TOPICS_SKIP: HashSet = TOPICS_TO_SKIP.clone(); pub static ref SYMBIOTIC_STAKING_TOPICS_SKIP: HashSet = TOPICS_TO_SKIP.clone(); + pub static ref STAKING_MANAGER_TOPICS_SKIP: HashSet = TOPICS_TO_SKIP.clone(); } diff --git a/matching_engine/src/log_processor/mod.rs b/matching_engine/src/log_processor/mod.rs index c42c440..004177c 100644 --- a/matching_engine/src/log_processor/mod.rs +++ b/matching_engine/src/log_processor/mod.rs @@ -3,4 +3,5 @@ pub mod er; pub mod gr; pub mod ns; pub mod pm; +pub mod sm; pub mod ss; diff --git a/matching_engine/src/log_processor/sm.rs b/matching_engine/src/log_processor/sm.rs new file mode 100644 index 0000000..9e140e4 --- /dev/null +++ b/matching_engine/src/log_processor/sm.rs @@ -0,0 +1,49 @@ +use ethers::prelude::{k256::ecdsa::SigningKey, *}; + +use crate::log_processor::constants; + +pub async fn process_staking_manager_log( + log: &Log, + staking_manager: &bindings::staking_manager::StakingManager< + SignerMiddleware, Wallet>, + >, +) -> Result<(), Box> { + if constants::STAKING_MANAGER_TOPICS_SKIP + .get(&log.topics[0]) + .is_some() + { + log::debug!("standard topic to skip found, ignoring it"); + return Ok(()); + } + + if let Ok(event_log) = + staking_manager.decode_event_raw("StakingPoolAdded", log.topics.clone(), log.data.clone()) + { + log::debug!("StakingPoolAdded Logs: {:?}", event_log); + let staking_pool = event_log.get(0).unwrap().clone().into_address().unwrap(); + log::warn!("Staking Pool Added: {}", staking_pool); + log::warn!("Dynamic stake pool management is not supported yet"); + return Ok(()); + } + + if let Ok(event_log) = + staking_manager.decode_event_raw("PoolRewardShareSet", log.topics.clone(), log.data.clone()) + { + log::debug!("PoolRewardShareSet Logs: {:?}", event_log); + return Ok(()); + } + + if let Ok(event_log) = + staking_manager.decode_event_raw("PoolEnabledSet", log.topics.clone(), log.data.clone()) + { + log::debug!("PoolEnabledSet Logs: {:?}", event_log); + let staking_pool = event_log.get(0).unwrap().clone().into_address().unwrap(); + let is_enabled = event_log.get(1).unwrap().clone().into_bool().unwrap(); + log::warn!("Staking Pool: {} is_enabled: {}", staking_pool, is_enabled); + + return Ok(()); + } + + log::error!("unhandled log in staking manager {:?}", log); + return Err("Unhandled log in staking manager".into()); +}