blueprint-client-eigenlayer 0.2.0-alpha.2

Eigenlayer client for Tangle Blueprints
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
use crate::error::Result;
use alloy_primitives::{Address, Bytes, U256};
use alloy_provider::{Provider, RootProvider};
use blueprint_evm_extra::util::{get_provider_http, get_wallet_provider_http};
use blueprint_runner::config::BlueprintEnvironment;
use blueprint_std::collections::HashMap;
use eigensdk::client_avsregistry::reader::AvsRegistryReader;
use eigensdk::common::get_ws_provider;
use eigensdk::utils::rewardsv2::middleware::registry_coordinator::RegistryCoordinator;
use eigensdk::utils::rewardsv2::middleware::stake_registry::{IStakeRegistry, StakeRegistry};
use eigensdk::utils::slashing::core::allocation_manager::{
    AllocationManager, IAllocationManagerTypes,
};
use eigensdk::utils::slashing::core::delegation_manager::DelegationManager;
use eigensdk::utils::slashing::middleware::operator_state_retriever::OperatorStateRetriever;
use num_bigint::BigInt;

/// Client that provides access to EigenLayer utility functions through the use of the [`BlueprintEnvironment`].
#[derive(Clone)]
pub struct EigenlayerClient {
    pub config: BlueprintEnvironment,
}

impl EigenlayerClient {
    /// Creates a new [`EigenlayerClient`].
    #[must_use]
    pub fn new(config: BlueprintEnvironment) -> Self {
        Self { config }
    }

    /// Get the [`BlueprintEnvironment`] for this client
    #[must_use]
    pub fn config(&self) -> &BlueprintEnvironment {
        &self.config
    }

    /// Get the provider for this client's http endpoint
    ///
    /// # Returns
    /// - [`The HTTP provider`](RootProvider)
    #[must_use]
    pub fn get_provider_http(&self) -> RootProvider {
        get_provider_http(self.config.http_rpc_endpoint.clone())
    }

    /// Get the provider for this client's http endpoint with the specified [`EthereumWallet`]
    ///
    /// # Returns
    /// - [`The HTTP wallet provider`](RootProvider)
    ///
    /// [`EthereumWallet`]: alloy_network::EthereumWallet
    #[must_use]
    pub fn get_wallet_provider_http(&self, wallet: alloy_network::EthereumWallet) -> RootProvider {
        get_wallet_provider_http(self.config.http_rpc_endpoint.clone(), wallet)
    }

    /// Get the provider for this client's websocket endpoint
    ///
    /// # Errors
    ///
    /// * Bad WS URL
    ///
    /// # Returns
    /// - [`The WS provider`](RootProvider<BoxTransport>)
    pub async fn get_provider_ws(&self) -> Result<RootProvider> {
        get_ws_provider(self.config.ws_rpc_endpoint.as_str())
            .await
            .map_err(Into::into)
    }

    // TODO: Slashing contracts equivalent
    // /// Get the slasher address from the `DelegationManager` contract
    // ///
    // /// # Returns
    // /// - [`Address`] - The slasher address
    // ///
    // /// # Errors
    // /// - [`Error::AlloyContract`] - If the call to the contract fails (i.e. the contract doesn't exist at the given address)
    // pub async fn get_slasher_address(&self, eigen_pod_manager_address: Address) -> Result<Address> {
    //     let provider = self.get_provider_http();
    //     let eigen_pod_manager =
    //         EigenPodManager::EigenPodManagerInstance::new(eigen_pod_manager_address, provider);
    //     eigen_pod_manager
    //         .slasher()
    //         .call()
    //         .await
    //         .map(|a| a._0)
    //         .map_err(Into::into)
    // }

    /// Provides a reader for the AVS registry.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    /// * See [`AvsRegistryChainReader::new()`]
    ///
    /// [`AvsRegistryChainReader::new()`]: eigensdk::client_avsregistry::reader::AvsRegistryChainReader::new
    pub async fn avs_registry_reader(
        &self,
    ) -> Result<eigensdk::client_avsregistry::reader::AvsRegistryChainReader> {
        let http_rpc_endpoint = self.config.http_rpc_endpoint.clone();
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let registry_coordinator_address = contract_addresses.registry_coordinator_address;
        let operator_state_retriever_address = contract_addresses.operator_state_retriever_address;
        eigensdk::client_avsregistry::reader::AvsRegistryChainReader::new(
            registry_coordinator_address,
            operator_state_retriever_address,
            http_rpc_endpoint.to_string(),
        )
        .await
        .map_err(Into::into)
    }

    /// Provides a writer for the AVS registry.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    /// * See [`AvsRegistryChainWriter::build_avs_registry_chain_writer()`]
    ///
    /// [`AvsRegistryChainWriter::build_avs_registry_chain_writer()`]: eigensdk::client_avsregistry::writer::AvsRegistryChainWriter::build_avs_registry_chain_writer
    pub async fn avs_registry_writer(
        &self,
        private_key: String,
    ) -> Result<eigensdk::client_avsregistry::writer::AvsRegistryChainWriter> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let registry_coordinator_address = contract_addresses.registry_coordinator_address;
        let service_manager_address = contract_addresses.service_manager_address;

        eigensdk::client_avsregistry::writer::AvsRegistryChainWriter::build_avs_registry_chain_writer(
            self.config.http_rpc_endpoint.to_string(),
            private_key,
            registry_coordinator_address,
            service_manager_address,
        ).await
        .map_err(Into::into)
    }

    /// Provides an operator info service.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    /// * See [`OperatorInfoServiceInMemory::new()`]
    ///
    /// [`OperatorInfoServiceInMemory::new()`]: eigensdk::services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory::new
    pub async fn operator_info_service_in_memory(
        &self,
    ) -> Result<(
        eigensdk::services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory,
        tokio::sync::mpsc::UnboundedReceiver<
            eigensdk::services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceError,
        >,
    )> {
        let avs_registry_reader = self.avs_registry_reader().await?;

        eigensdk::services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory::new(
            avs_registry_reader,
            self.config.ws_rpc_endpoint.to_string(),
        )
        .await
        .map_err(Into::into)
    }

    /// Provides an AVS registry service chain caller.
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_reader()`]
    /// * See [`Self::operator_info_service_in_memory()`]
    pub async fn avs_registry_service_chain_caller_in_memory(
        &self,
    ) -> Result<
        eigensdk::services_avsregistry::chaincaller::AvsRegistryServiceChainCaller<
            eigensdk::client_avsregistry::reader::AvsRegistryChainReader,
            eigensdk::services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory,
        >,
    > {
        let avs_registry_reader = self.avs_registry_reader().await?;
        let (operator_info_service, _) = self.operator_info_service_in_memory().await?;

        let cancellation_token = tokio_util::sync::CancellationToken::new();
        let token_clone = cancellation_token.clone();
        let provider = self.get_provider_http();
        let current_block = provider.get_block_number().await?;
        let operator_info_clone = operator_info_service.clone();

        tokio::task::spawn(async move {
            operator_info_clone
                .start_service(&token_clone, 0, current_block)
                .await
        });

        Ok(
            eigensdk::services_avsregistry::chaincaller::AvsRegistryServiceChainCaller::new(
                avs_registry_reader,
                operator_info_service,
            ),
        )
    }

    /// Provides a BLS aggregation service.
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_service_chain_caller_in_memory()`]
    pub async fn bls_aggregation_service_in_memory(&self) -> Result<eigensdk::services_blsaggregation::bls_agg::BlsAggregatorService<
        eigensdk::services_avsregistry::chaincaller::AvsRegistryServiceChainCaller<
            eigensdk::client_avsregistry::reader::AvsRegistryChainReader,
            eigensdk::services_operatorsinfo::operatorsinfo_inmemory::OperatorInfoServiceInMemory
        >
    >>{
        let avs_registry_service = self.avs_registry_service_chain_caller_in_memory().await?;
        Ok(
            eigensdk::services_blsaggregation::bls_agg::BlsAggregatorService::new(
                avs_registry_service,
            ),
        )
    }

    /// Get Operator stake in Quorums at a given block.
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_reader()`]
    /// * See [`AvsRegistryChainReader::get_operators_stake_in_quorums_at_block()`]
    ///
    /// [`AvsRegistryChainReader::get_operators_stake_in_quorums_at_block()`]: eigensdk::client_avsregistry::reader::AvsRegistryChainReader::get_operators_stake_in_quorums_at_block
    pub async fn get_operator_stake_in_quorums_at_block(
        &self,
        block_number: u32,
        quorum_numbers: Bytes,
    ) -> Result<Vec<Vec<OperatorStateRetriever::Operator>>> {
        self.avs_registry_reader()
            .await?
            .get_operators_stake_in_quorums_at_block(block_number.into(), quorum_numbers)
            .await
            .map_err(Into::into)
    }

    /// Get an Operator's stake in Quorums at current block.
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_reader()`]
    /// * See [`AvsRegistryChainReader::get_operator_stake_in_quorums_of_operator_at_current_block()`]
    ///
    /// [`AvsRegistryChainReader::get_operator_stake_in_quorums_of_operator_at_current_block()`]: eigensdk::client_avsregistry::reader::AvsRegistryChainReader::get_operator_stake_in_quorums_of_operator_at_current_block
    pub async fn get_operator_stake_in_quorums_at_current_block(
        &self,
        operator_id: alloy_primitives::FixedBytes<32>,
    ) -> Result<HashMap<u8, BigInt>> {
        self.avs_registry_reader()
            .await?
            .get_operator_stake_in_quorums_of_operator_at_current_block(operator_id)
            .await
            .map_err(Into::into)
    }

    /// Get an Operator by ID.
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_reader()`]
    /// * See [`AvsRegistryReader::get_operator_from_id()`]
    pub async fn get_operator_by_id(&self, operator_id: [u8; 32]) -> Result<Address> {
        self.avs_registry_reader()
            .await?
            .get_operator_from_id(operator_id)
            .await
            .map_err(Into::into)
    }

    /// Get an Operator stake history.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    pub async fn get_operator_stake_history(
        &self,
        operator_id: alloy_primitives::FixedBytes<32>,
        quorum_number: u8,
    ) -> Result<Vec<IStakeRegistry::StakeUpdate>> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();
        let registry_coordinator = RegistryCoordinator::new(
            contract_addresses.registry_coordinator_address,
            provider.clone(),
        );
        let stake_registry_address = registry_coordinator.stakeRegistry().call().await?;
        let instance =
            StakeRegistry::StakeRegistryInstance::new(stake_registry_address, provider.clone());
        let call_builder = instance.getStakeHistory(operator_id, quorum_number);
        let response = call_builder.call().await?;
        Ok(response)
    }

    /// Get an Operator stake update at a given index.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    pub async fn get_operator_stake_update_at_index(
        &self,
        quorum_number: u8,
        operator_id: alloy_primitives::FixedBytes<32>,
        index: alloy_primitives::U256,
    ) -> Result<IStakeRegistry::StakeUpdate> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();
        let registry_coordinator = RegistryCoordinator::new(
            contract_addresses.registry_coordinator_address,
            provider.clone(),
        );
        let stake_registry_address = registry_coordinator.stakeRegistry().call().await?;
        let instance =
            StakeRegistry::StakeRegistryInstance::new(stake_registry_address, provider.clone());
        let call_builder = instance.getStakeUpdateAtIndex(quorum_number, operator_id, index);
        let response = call_builder.call().await?;
        Ok(response)
    }

    /// Get an Operator's stake at a given block number.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    pub async fn get_operator_stake_at_block_number(
        &self,
        operator_id: alloy_primitives::FixedBytes<32>,
        quorum_number: u8,
        block_number: u32,
    ) -> Result<alloy_primitives::Uint<96, 2>> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();
        let registry_coordinator = RegistryCoordinator::new(
            contract_addresses.registry_coordinator_address,
            provider.clone(),
        );
        let stake_registry_address = registry_coordinator.stakeRegistry().call().await?;
        let instance =
            StakeRegistry::StakeRegistryInstance::new(stake_registry_address, provider.clone());
        let call_builder = instance.getStakeAtBlockNumber(operator_id, quorum_number, block_number);
        let response = call_builder.call().await?;
        Ok(response)
    }

    // TODO: Slashing contract equivalent
    // /// Get an Operator's [`details`](OperatorDetails).
    // pub async fn get_operator_details(
    //     &self,
    //     operator_addr: Address,
    // ) -> Result<eigensdk::types::operator::Operator> {
    //     let http_rpc_endpoint = self.config.http_rpc_endpoint.clone();
    //     let contract_addresses = self.config.protocol_settings.eigenlayer()?;
    //     let chain_reader = eigensdk::client_elcontracts::reader::ELChainReader::new(
    //         Some(contract_addresses.allocation_manager_address),
    //         contract_addresses.delegation_manager_address,
    //         contract_addresses.rewards_coordinator_address,
    //         contract_addresses.avs_directory_address,
    //         Some(contract_addresses.permission_controller_address),
    //         http_rpc_endpoint.clone(),
    //     );
    //     Ok(chain_reader.get_operator_details(operator_addr).await?)
    // }

    /// Get an Operator's latest stake update.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    pub async fn get_latest_stake_update(
        &self,
        operator_id: alloy_primitives::FixedBytes<32>,
        quorum_number: u8,
    ) -> Result<IStakeRegistry::StakeUpdate> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();
        let registry_coordinator = RegistryCoordinator::new(
            contract_addresses.registry_coordinator_address,
            provider.clone(),
        );
        let stake_registry_address = registry_coordinator.stakeRegistry().call().await?;
        let instance =
            StakeRegistry::StakeRegistryInstance::new(stake_registry_address, provider.clone());
        let call_builder = instance.getLatestStakeUpdate(operator_id, quorum_number);
        let response = call_builder.call().await?;
        Ok(response)
    }

    /// Get an Operator's ID as [`FixedBytes`] from its [`Address`].
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_reader()`]
    /// * See [`AvsRegistryChainReader::get_operator_id()`]
    ///
    /// [`FixedBytes`]: alloy_primitives::FixedBytes
    /// [`AvsRegistryChainReader::get_operator_id()`]: eigensdk::client_avsregistry::reader::AvsRegistryChainReader::get_operator_id
    pub async fn get_operator_id(
        &self,
        operator_addr: Address,
    ) -> Result<alloy_primitives::FixedBytes<32>> {
        self.avs_registry_reader()
            .await?
            .get_operator_id(operator_addr)
            .await
            .map_err(Into::into)
    }

    /// Get the total stake at a given block number from a given index.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    pub async fn get_total_stake_at_block_number_from_index(
        &self,
        quorum_number: u8,
        block_number: u32,
        index: alloy_primitives::U256,
    ) -> Result<alloy_primitives::Uint<96, 2>> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();
        let registry_coordinator = RegistryCoordinator::new(
            contract_addresses.registry_coordinator_address,
            provider.clone(),
        );
        let stake_registry_address = registry_coordinator.stakeRegistry().call().await?;
        let instance =
            StakeRegistry::StakeRegistryInstance::new(stake_registry_address, provider.clone());
        let call_builder =
            instance.getTotalStakeAtBlockNumberFromIndex(quorum_number, block_number, index);
        let response = call_builder.call().await?;
        Ok(response)
    }

    /// Get the total stake history length of a given quorum.
    ///
    /// # Errors
    ///
    /// * The [`BlueprintEnvironment`] is not configured for Eigenlayer
    pub async fn get_total_stake_history_length(
        &self,
        quorum_number: u8,
    ) -> Result<alloy_primitives::U256> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();
        let registry_coordinator = RegistryCoordinator::new(
            contract_addresses.registry_coordinator_address,
            provider.clone(),
        );
        let stake_registry_address = registry_coordinator.stakeRegistry().call().await?;
        let instance =
            StakeRegistry::StakeRegistryInstance::new(stake_registry_address, provider.clone());
        let call_builder = instance.getTotalStakeHistoryLength(quorum_number);
        let response = call_builder.call().await?;
        Ok(response)
    }

    /// Provides the public keys of existing registered operators within the provided block range.
    ///
    /// # Errors
    ///
    /// * See [`Self::avs_registry_reader()`]
    /// * See [`AvsRegistryChainReader::query_existing_registered_operator_pub_keys()`]
    ///
    /// [`AvsRegistryChainReader::query_existing_registered_operator_pub_keys()`]: eigensdk::client_avsregistry::reader::AvsRegistryChainReader::query_existing_registered_operator_pub_keys
    pub async fn query_existing_registered_operator_pub_keys(
        &self,
        start_block: u64,
        to_block: u64,
    ) -> Result<(
        Vec<Address>,
        Vec<eigensdk::types::operator::OperatorPubKeys>,
    )> {
        self.avs_registry_reader()
            .await?
            .query_existing_registered_operator_pub_keys(
                start_block,
                to_block,
                self.config.ws_rpc_endpoint.to_string(),
            )
            .await
            .map_err(Into::into)
    }

    /// Get strategies in an operator set (quorum) for a given AVS.
    ///
    /// # Arguments
    ///
    /// * `avs_address` - The address of the AVS service manager
    /// * `operator_set_id` - The ID of the operator set (quorum number)
    ///
    /// # Returns
    ///
    /// A vector of strategy addresses used in the specified operator set
    ///
    /// # Errors
    ///
    /// * [`Error::AlloyContractError`] - If the call to the contract fails
    pub async fn get_strategies_in_operator_set(
        &self,
        avs_address: Address,
        operator_set_id: u8,
    ) -> Result<Vec<Address>> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();

        let allocation_manager = AllocationManager::AllocationManagerInstance::new(
            contract_addresses.allocation_manager_address,
            provider,
        );

        let operator_set = AllocationManager::OperatorSet {
            avs: avs_address,
            id: u32::from(operator_set_id), // Convert u8 to u32
        };

        let result = allocation_manager
            .getStrategiesInOperatorSet(operator_set)
            .call()
            .await?;

        Ok(result)
    }

    /// Get strategy allocations for a specific operator and strategy.
    ///
    /// # Arguments
    ///
    /// * `operator_address` - The address of the operator
    /// * `strategy_address` - The address of the strategy
    ///
    /// # Returns
    ///
    /// A tuple containing:
    /// - A vector of operator sets the operator is part of
    /// - A vector of allocations for each operator set
    ///
    /// # Errors
    ///
    /// * [`Error::AlloyContractError`] - If the call to the contract fails
    pub async fn get_strategy_allocations(
        &self,
        operator_address: Address,
        strategy_address: Address,
    ) -> Result<(
        Vec<AllocationManager::OperatorSet>,
        Vec<IAllocationManagerTypes::Allocation>,
    )> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();

        let allocation_manager = AllocationManager::AllocationManagerInstance::new(
            contract_addresses.allocation_manager_address,
            provider,
        );

        let result = allocation_manager
            .getStrategyAllocations(operator_address, strategy_address)
            .call()
            .await?;

        Ok((result._0, result._1))
    }

    /// Get the maximum magnitude for a specific operator and strategy.
    ///
    /// # Arguments
    ///
    /// * `operator_address` - The address of the operator
    /// * `strategy_address` - The address of the strategy
    ///
    /// # Returns
    ///
    /// The maximum magnitude
    ///
    /// # Errors
    ///
    /// * [`Error::AlloyContractError`] - If the call to the contract fails
    pub async fn get_max_magnitude(
        &self,
        operator_address: Address,
        strategy_address: Address,
    ) -> Result<u64> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();

        let allocation_manager = AllocationManager::AllocationManagerInstance::new(
            contract_addresses.allocation_manager_address,
            provider,
        );

        let result = allocation_manager
            .getMaxMagnitude(operator_address, strategy_address)
            .call()
            .await?;

        Ok(result)
    }

    /// Get slashable shares in queue for a specific operator and strategy.
    ///
    /// # Arguments
    ///
    /// * `operator_address` - The address of the operator
    /// * `strategy_address` - The address of the strategy
    ///
    /// # Returns
    ///
    /// The amount of slashable shares in the queue
    ///
    /// # Errors
    ///
    /// * [`Error::AlloyContractError`] - If the call to the contract fails
    pub async fn get_slashable_shares_in_queue(
        &self,
        operator_address: Address,
        strategy_address: Address,
    ) -> Result<U256> {
        let contract_addresses = self.config.protocol_settings.eigenlayer()?;
        let provider = self.get_provider_http();

        let delegation_manager = DelegationManager::DelegationManagerInstance::new(
            contract_addresses.delegation_manager_address,
            provider,
        );

        let result = delegation_manager
            .getSlashableSharesInQueue(operator_address, strategy_address)
            .call()
            .await?;

        Ok(result)
    }

    /// Get all operators for a service at a specific block.
    ///
    /// # Arguments
    ///
    /// * `avs_address` - The address of the AVS service manager
    /// * `block_number` - The block number to retrieve the operators at
    /// * `quorum_numbers` - The quorum numbers to retrieve operators for
    ///
    /// # Returns
    ///
    /// A vector of vectors containing operators in each quorum
    ///
    /// # Errors
    ///
    /// * [`Error::AlloyContractError`] - If the call to the contract fails
    pub async fn get_operators_for_service(
        &self,
        _avs_address: Address,
        block_number: u32,
        quorum_numbers: Vec<u8>,
    ) -> Result<Vec<Vec<OperatorStateRetriever::Operator>>> {
        let quorum_bytes = Bytes::from(quorum_numbers);
        self.get_operator_stake_in_quorums_at_block(block_number, quorum_bytes)
            .await
    }

    /// Get all slashable assets for an AVS.
    ///
    /// # Arguments
    ///
    /// * `avs_address` - The address of the AVS service manager
    /// * `block_number` - The block number to retrieve the data at
    /// * `quorum_numbers` - The quorum numbers (operator set IDs) to retrieve data for
    ///
    /// # Returns
    ///
    /// A hashmap where:
    /// - Key: Operator address
    /// - Value: A hashmap where:
    ///   - Key: Strategy address
    ///   - Value: Amount of slashable shares
    ///
    /// # Errors
    ///
    /// * [`Error::AlloyContractError`] - If any contract call fails
    pub async fn get_slashable_assets_for_avs(
        &self,
        avs_address: Address,
        block_number: u32,
        quorum_numbers: Vec<u8>,
    ) -> Result<HashMap<Address, HashMap<Address, U256>>> {
        let mut result = HashMap::new();

        let all_operator_info = self
            .get_operators_for_service(avs_address, block_number, quorum_numbers.clone())
            .await?;

        for (operators, quorum_number) in all_operator_info.iter().zip(quorum_numbers) {
            let strategies = self
                .get_strategies_in_operator_set(avs_address, quorum_number)
                .await?;

            for operator in operators {
                let operator_id = operator.operatorId;

                let operator_address = self.get_operator_by_id(operator_id.into()).await?;

                let operator_entry = result.entry(operator_address).or_insert_with(HashMap::new);

                for strategy_address in &strategies {
                    match self
                        .get_slashable_shares_in_queue(operator_address, *strategy_address)
                        .await
                    {
                        Ok(slashable_shares) => {
                            operator_entry.insert(*strategy_address, slashable_shares);
                        }
                        Err(e) => {
                            // Log the error but continue with other strategies
                            blueprint_core::error!(
                                "Error getting slashable shares for operator {operator_address}, strategy {strategy_address}: {e}",
                            );
                        }
                    }
                }
            }
        }

        Ok(result)
    }
}