Skip to content

Commit

Permalink
listen staking manager events
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Nov 15, 2024
1 parent 70fe325 commit 081c4cb
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion matching_engine/src/generator_lib/generator_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ mod tests {

pub static TEST_TOKEN_ADDRESS_TWO: Lazy<Address> =
Lazy::new(|| TEST_TOKEN_ADDRESS_TWO_STRING.parse::<Address>().unwrap());

#[allow(unused)]
pub static TEST_TOKEN_ADDRESS_THREE: Lazy<Address> =
Lazy::new(|| TEST_TOKEN_ADDRESS_THREE_STRING.parse::<Address>().unwrap());
Expand Down
18 changes: 18 additions & 0 deletions matching_engine/src/jobs/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type SymbioticStakingInstance = bindings::symbiotic_staking::SymbioticStaking<
type NativeStakingInstance =
bindings::native_staking::NativeStaking<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>;

type StakingManagerInstance =
bindings::staking_manager::StakingManager<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>;

pub struct LogParser {
should_stop: Arc<AtomicBool>,
start_block: Arc<RwLock<U64>>,
Expand All @@ -61,6 +64,7 @@ pub struct LogParser {
entity_registry: EntityRegistryInstance,
symbiotic_staking: SymbioticStakingInstance,
native_staking: NativeStakingInstance,
staking_manager: StakingManagerInstance,
provider_http: Arc<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>,
matching_engine_key: Vec<u8>,
matching_engine_slave_keys: Vec<Vec<u8>>,
Expand Down Expand Up @@ -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<String>,
shared_local_ask_store: Arc<RwLock<LocalAskStore>>,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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"));
}
Expand Down
14 changes: 14 additions & 0 deletions matching_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
Expand All @@ -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<u16>,
) -> Self {
Expand All @@ -166,6 +173,7 @@ impl MatchingEngine {
entity_registry,
symbiotic_staking,
native_staking,
staking_manager,
start_block,
};

Expand Down Expand Up @@ -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"),
));
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions matching_engine/src/log_processor/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ lazy_static! {
pub static ref ENTITY_KEY_REGISTRY_TOPICS_SKIP: HashSet<H256> = TOPICS_TO_SKIP.clone();
pub static ref NATIVE_STAKING_TOPICS_SKIP: HashSet<H256> = TOPICS_TO_SKIP.clone();
pub static ref SYMBIOTIC_STAKING_TOPICS_SKIP: HashSet<H256> = TOPICS_TO_SKIP.clone();
pub static ref STAKING_MANAGER_TOPICS_SKIP: HashSet<H256> = TOPICS_TO_SKIP.clone();
}
1 change: 1 addition & 0 deletions matching_engine/src/log_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod er;
pub mod gr;
pub mod ns;
pub mod pm;
pub mod sm;
pub mod ss;
49 changes: 49 additions & 0 deletions matching_engine/src/log_processor/sm.rs
Original file line number Diff line number Diff line change
@@ -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<Provider<Http>, Wallet<SigningKey>>,
>,
) -> Result<(), Box<dyn std::error::Error>> {
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());
}

0 comments on commit 081c4cb

Please sign in to comment.