eigen_services_operatorsinfo/lib.rs
1//! Operators Info Service
2//!
3//! This crate provides traits and methods to get operator information.
4//!
5//! ## Introduction
6//!
7//! The Operators Info Service provides functionality to get operators Public Keys and Sockets.
8//!
9//! The service is designed to be used in conjunction with the `AvsRegistryServiceChainCaller`
10//! to get the operators information from the chain.
11//!
12//! ## Main Components
13//!
14//! ### OperatorInfoServiceInMemory
15//!
16//! The main struct of the service, it implements the [`OperatorInfoService`] trait.
17//! It fetches and stores operators info (addresses and public key) in memory.
18//!
19//! - `avs_registry_reader`: `AvsRegistryChainReader` to get the operators information from the chain
20//!
21//! ### OperatorSocket
22//!
23//! Represents an operator with the ID and the socket.
24//!
25//! - `id`: Operator ID
26//! - `socket`: Operator socket
27//!
28//! ### OperatorPubKeys
29//!
30//! Represents the operator public keys.
31//!
32//! - `g1_pub_key`: Operator G1 public key
33//! - `g2_pub_key`: Operator G2 public key
34//!
35//! ## Usage
36//!
37//! ### Initialize the Service
38//!
39//! When using the [`OperatorInfoServiceInMemory`] struct, you can initialize the service by calling the
40//! [`new`] method. This method returns a tuple of the service and a channel to receive errors from the service. Also,
41//! it creates a background task to process the `OperatorsInfoMessage`. The messages that the service will process are:
42//! - `InsertOperatorInfo`: Save the operator info in memory.
43//! - `Remove`: Remove the operator info from state.
44//! - `GetPubKeys`: Get the operator public keys from memory.
45//! - `GetSockets`: Get the operator socket from memory.
46//!
47//! ```rust,no_run
48//!# use eigen_testing_utils::anvil_constants::{
49//!# ANVIL_HTTP_URL, ANVIL_WS_URL,
50//!# get_operator_state_retriever_address, get_registry_coordinator_address,
51//!# };
52//!# use eigen_services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory;
53//!# use eigen_client_avsregistry::reader::AvsRegistryChainReader;
54//!# async fn example () {
55//!# let http_endpoint = ANVIL_HTTP_URL;
56//!# let ws_endpoint = ANVIL_WS_URL;
57//!#
58//!# let registry_coordinator_address = get_registry_coordinator_address(http_endpoint.to_string()).await;
59//!# let operator_state_retriever_address = get_operator_state_retriever_address(http_endpoint.to_string()).await;
60//!#
61//!# let avs_registry_chain_reader = AvsRegistryChainReader::new(
62//!# registry_coordinator_address,
63//!# operator_state_retriever_address,
64//!# http_endpoint.to_string(),
65//!# )
66//!# .await
67//!# .unwrap();
68//!#
69//! let operators_info_service_in_memory = OperatorInfoServiceInMemory::new(
70//! avs_registry_chain_reader,
71//! ws_endpoint.to_string(),
72//! )
73//! .await
74//! .unwrap();
75//!# }
76//! ```
77//!
78//! ### Start the Service
79//!
80//! Then you can start the service by calling the [`start_service`] method. It will listen to events of `NEW_PUBKEY_REGISTRATION_EVENT`
81//! and `OPERATOR_SOCKET_UPDATE` and save the data in memory. To stop the service, you can use the `CancellationToken`.
82//!
83//! ```rust,no_run
84//!# use eigen_testing_utils::anvil_constants::{
85//!# ANVIL_HTTP_URL, ANVIL_WS_URL,
86//!# get_operator_state_retriever_address, get_registry_coordinator_address,
87//!# };
88//!# use eigen_services_operatorsinfo::{
89//!# operator_info::OperatorInfoService, operatorsinfo_inmemory::OperatorInfoServiceInMemory,
90//!# };
91//!# use eigen_client_avsregistry::reader::AvsRegistryChainReader;
92//!# async fn example () {
93//!# let http_endpoint = ANVIL_HTTP_URL;
94//!# let ws_endpoint = ANVIL_WS_URL;
95//!#
96//!# let registry_coordinator_address = get_registry_coordinator_address(http_endpoint.to_string()).await;
97//!# let operator_state_retriever_address = get_operator_state_retriever_address(http_endpoint.to_string()).await;
98//!#
99//!# let avs_registry_chain_reader = AvsRegistryChainReader::new(
100//!# registry_coordinator_address,
101//!# operator_state_retriever_address,
102//!# http_endpoint.to_string(),
103//!# )
104//!# .await
105//!# .unwrap();
106//!#
107//!# let operators_info_service_in_memory = OperatorInfoServiceInMemory::new(
108//!# avs_registry_chain_reader,
109//!# ws_endpoint.to_string(),
110//!# )
111//!# .await
112//!# .unwrap()
113//!# .0;
114//!#
115//!# let clone_operators_info = operators_info_service_in_memory.clone();
116//!# let cancellation_token = tokio_util::sync::CancellationToken::new();
117//!# let cloned_token = cancellation_token.clone();
118//!# let cloned_http_endpoint = http_endpoint.clone();
119//!# let end_block = 100;
120//!#
121//! tokio::spawn(async move {
122//! let _ = clone_operators_info
123//! .start_service(
124//! &cloned_token,
125//! 0,
126//! end_block,
127//! )
128//! .await;
129//! });
130//!# }
131//! ```
132//!
133//! ### Query Past Operator Registration Events and Fill the Database
134//!
135//! To query past operator registration events and fill the database, you can call the [`query_past_registered_operator_events_and_fill_db`] method.
136//! This function will send a `OperatorsInfoMessage` with the `InsertOperatorInfo` action to the service channel and store the data in `OperatorState`.
137//!
138//! ```rust,no_run
139//!# use eigen_testing_utils::anvil_constants::{
140//!# ANVIL_HTTP_URL, ANVIL_WS_URL,
141//!# get_operator_state_retriever_address, get_registry_coordinator_address,
142//!# };
143//!# use eigen_services_operatorsinfo::{
144//!# operator_info::OperatorInfoService, operatorsinfo_inmemory::OperatorInfoServiceInMemory,
145//!# };
146//!# use eigen_client_avsregistry::reader::AvsRegistryChainReader;
147//!# async fn example () {
148//!# let http_endpoint = ANVIL_HTTP_URL;
149//!# let ws_endpoint = ANVIL_WS_URL;
150//!#
151//!# let registry_coordinator_address = get_registry_coordinator_address(http_endpoint.to_string()).await;
152//!# let operator_state_retriever_address = get_operator_state_retriever_address(http_endpoint.to_string()).await;
153//!#
154//!# let avs_registry_chain_reader = AvsRegistryChainReader::new(
155//!# registry_coordinator_address,
156//!# operator_state_retriever_address,
157//!# http_endpoint.to_string(),
158//!# )
159//!# .await
160//!# .unwrap();
161//!#
162//!# let operators_info_service_in_memory = OperatorInfoServiceInMemory::new(
163//!# avs_registry_chain_reader,
164//!# ws_endpoint.to_string(),
165//!# )
166//!# .await
167//!# .unwrap()
168//!# .0;
169//!#
170//!# let end_block = 100;
171//! operators_info_service_in_memory
172//! .query_past_registered_operator_events_and_fill_db(0, end_block)
173//! .await;
174//!# }
175//! ```
176//!
177//! ### Retrieve Operator information
178//!
179//! To retrieve operator information, you can call the [`get_operator_info`] or [`get_operator_socket`] methods.
180//!
181//! ```rust,no_run
182//!# use alloy::primitives::{Address};
183//!# use eigen_testing_utils::anvil_constants::{
184//!# ANVIL_HTTP_URL, ANVIL_WS_URL, FIRST_ADDRESS,
185//!# get_operator_state_retriever_address, get_registry_coordinator_address,
186//!# };
187//!# use eigen_services_operatorsinfo::{
188//!# operator_info::OperatorInfoService, operatorsinfo_inmemory::OperatorInfoServiceInMemory,
189//!# };
190//!# use eigen_client_avsregistry::reader::AvsRegistryChainReader;
191//!# async fn example () {
192//!# let http_endpoint = ANVIL_HTTP_URL;
193//!# let ws_endpoint = ANVIL_WS_URL;
194//!#
195//!# let registry_coordinator_address = get_registry_coordinator_address(http_endpoint.to_string()).await;
196//!# let operator_state_retriever_address = get_operator_state_retriever_address(http_endpoint.to_string()).await;
197//!#
198//!# let avs_registry_chain_reader = AvsRegistryChainReader::new(
199//!# registry_coordinator_address,
200//!# operator_state_retriever_address,
201//!# http_endpoint.to_string(),
202//!# )
203//!# .await
204//!# .unwrap();
205//!#
206//!# let operators_info_service_in_memory = OperatorInfoServiceInMemory::new(
207//!# avs_registry_chain_reader,
208//!# ws_endpoint.to_string(),
209//!# )
210//!# .await
211//!# .unwrap()
212//!# .0;
213//!#
214//!# let operator_address = Address::from(FIRST_ADDRESS);
215//!#
216//! let operator_info = operators_info_service_in_memory
217//! .get_operator_info(operator_address)
218//! .await
219//! .unwrap()
220//! .unwrap();
221//!#
222//! let operator_socket = operators_info_service_in_memory
223//! .get_operator_socket(operator_address)
224//! .await
225//! .unwrap()
226//! .unwrap();
227//!# }
228//! ```
229//!
230//! [`OperatorInfoServiceInMemory`]: operatorsinfo_inmemory::OperatorInfoServiceInMemory
231//! [`OperatorInfoService`]: operator_info::OperatorInfoService
232//! [`new`]: operatorsinfo_inmemory::OperatorInfoServiceInMemory::new()
233//! [`start_service`]: operatorsinfo_inmemory::OperatorInfoServiceInMemory::start_service()
234//! [`query_past_registered_operator_events_and_fill_db`]: operatorsinfo_inmemory::OperatorInfoServiceInMemory::query_past_registered_operator_events_and_fill_db()
235//! [`get_operator_info`]: operator_info::OperatorInfoService::get_operator_info()
236//! [`get_operator_socket`]: operator_info::OperatorInfoService::get_operator_socket()
237
238#![doc(
239 html_logo_url = "https://github.com/Layr-Labs/eigensdk-rs/assets/91280922/bd13caec-3c00-4afc-839a-b83d2890beb5",
240 issue_tracker_base_url = "https://github.com/Layr-Labs/eigensdk-rs/issues/"
241)]
242#![cfg_attr(not(test), warn(unused_crate_dependencies))]
243
244#[doc(hidden)]
245pub mod fake_operator_info;
246pub mod operator_info;
247pub mod operatorsinfo_inmemory;
248pub mod operatorsinfo_onchain;