Skip to content

Commit

Permalink
feat: Implement missing stake registry view functions (#347)
Browse files Browse the repository at this point in the history
Fixes #314 

### What Changed?
<!-- Describe the changes made in this pull request -->

### Reviewer Checklist

- [ ] New features are tested and documented
- [ ] PR updates the changelog with a description of changes
- [ ] PR has one of the `changelog-X` labels (if applies)
- [ ] Code deprecates any old functionality before removing it
  • Loading branch information
supernovahs authored Feb 12, 2025
1 parent 4cf1969 commit 295b462
Show file tree
Hide file tree
Showing 5 changed files with 856 additions and 87 deletions.
144 changes: 144 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,150 @@ Those changes in added, changed or breaking changes, should include usage exampl
.await
.unwrap();
```
* Added missing stake registry view methods in `avsregistry/reader` in [#347](https://github.com/Layr-Labs/eigensdk-rs/pull/347).

* `weight_of_operator_for_quorum`

```rust
let weight = avs_reader
.weight_of_operator_for_quorum(quorum_number, operator_address)
.await
.unwrap();
```

* `strategy_params_length`

```rust
let len = avs_reader
.strategy_params_length(quorum_number)
.await
.unwrap();
```

* `strategy_params_by_index`

```rust
let params = avs_reader
.strategy_params_by_index(quorum_number, index)
.await
.unwrap();
```

* `get_stake_history_length`

```rust
let len = avs_reader
.get_stake_history_length(operator_id, quorum_number)
.await
.unwrap();
```

* `get_stake_history`

```rust
let stake_update_vec = avs_reader
.get_stake_history(operator_id, quorum_number)
.await
.unwrap();
```
* `get_latest_stake_update`

```rust
let latest_stake_update = avs_reader
.get_latest_stake_update(operator_id, quorum_number)
.await
.unwrap();
```
* `get_stake_update_at_index`

```rust
let stake_update = avs_reader
.get_stake_update_at_index(quorum_number, operator_id, index)
.await
.unwrap();
```

* `get_stake_update_at_block_number`

```rust
let stake_update_at_index = avs_reader
.get_stake_update_at_block_number(operator_id, quorum_number, (block_number) as u32)
.await
.unwrap();
```

* `get_stake_update_index_at_block_number`

```rust
let stake_update_at_index_at_block_number = avs_reader
.get_stake_update_index_at_block_number(operator_id, quorum_number, block_number as u32)
.await
.unwrap();
```

* `get_stake_at_block_number_and_index`

```rust
let stake_at_index_at_block_number = avs_reader
.get_stake_at_block_number_and_index(
quorum_number,
block_number as u32,
operator_id,
index,
)
.await
.unwrap();
```

* `get_total_stake_history_length`

```rust
let total_stake_history_length = avs_reader
.get_total_stake_history_length(quorum_number)
.await
.unwrap();
```

* `get_current_total_stake`

```rust
let current_total_stake = avs_reader
.get_current_total_stake(quorum_number)
.await
.unwrap();

```

* `get_total_stake_update_at_index`

```rust
let total_stake_update_at_index = avs_reader
.get_total_stake_update_at_index(quorum_number, index)
.await
.unwrap();
```

* `get_total_stake_at_block_number_from_index`

```rust
let total_stake_at_block_number_from_index = avs_reader
.get_total_stake_at_block_number_from_index(
quorum_number,
block_number as u32,
index,
)
.await
.unwrap();
```

* `get_total_stake_indices_at_block_number`

```rust
let total_stake_indices_at_block_number = avs_reader
.get_total_stake_indices_at_block_number(block_number as u32, quorum_nums)
.await
.unwrap();
```

### Changed

Expand Down
66 changes: 62 additions & 4 deletions crates/chainio/clients/avsregistry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ pub mod fake_reader;

#[cfg(test)]
pub(crate) mod test_utils {
use crate::writer::AvsRegistryChainWriter;
use alloy::{
primitives::{aliases::U96, Address},
primitives::{aliases::U96, Address, Bytes, FixedBytes, U256},
providers::WalletProvider,
sol_types::SolCall,
};
use eigen_common::get_signer;
use eigen_crypto_bls::BlsKeyPair;
use eigen_logging::get_test_logger;
use eigen_testing_utils::anvil_constants::{
get_allocation_manager_address, get_erc20_mock_strategy,
get_operator_state_retriever_address, get_registry_coordinator_address,
get_service_manager_address, FIRST_PRIVATE_KEY,
};
use eigen_testing_utils::transaction::wait_transaction;
use eigen_utils::slashing::{
core::allocationmanager::AllocationManager,
middleware::registrycoordinator::{
Expand All @@ -43,9 +46,6 @@ pub(crate) mod test_utils {

use crate::reader::AvsRegistryChainReader;

pub(crate) const OPERATOR_BLS_KEY: &str =
"1371012690269088913462269866874713266643928125698382731338806296762673180359922";

pub(crate) async fn create_operator_set(http_endpoint: &str, avs_address: Address) {
let allocation_manager_addr =
get_allocation_manager_address(http_endpoint.to_string()).await;
Expand Down Expand Up @@ -131,4 +131,62 @@ pub(crate) mod test_utils {
.await
.unwrap()
}

pub(crate) async fn build_avs_registry_chain_writer(
http_endpoint: String,
private_key: String,
) -> AvsRegistryChainWriter {
let registry_coordinator_address =
get_registry_coordinator_address(http_endpoint.clone()).await;
let operator_state_retriever_address =
get_operator_state_retriever_address(http_endpoint.clone()).await;
AvsRegistryChainWriter::build_avs_registry_chain_writer(
get_test_logger(),
http_endpoint,
private_key,
registry_coordinator_address,
operator_state_retriever_address,
)
.await
.unwrap()
}

// this function is called from test_avs_writer_methods
pub(crate) async fn test_register_operator(
avs_writer: &AvsRegistryChainWriter,
private_key_decimal: String,
quorum_nums: Bytes,
http_url: String,
) {
let bls_key_pair = BlsKeyPair::new(private_key_decimal).unwrap();
let digest_hash: FixedBytes<32> = FixedBytes::from([0x02; 32]);

// this is set to U256::MAX so that the registry does not take the signature as expired.
let signature_expiry = U256::MAX;
let tx_hash = avs_writer
.register_operator_in_quorum_with_avs_registry_coordinator(
bls_key_pair,
digest_hash,
signature_expiry,
quorum_nums.clone(),
"".into(),
)
.await
.unwrap();

let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}

// this function is caller from test_avs_writer_methods
pub(crate) async fn test_deregister_operator(
avs_writer: &AvsRegistryChainWriter,
quorum_nums: Bytes,
http_url: String,
) {
let tx_hash = avs_writer.deregister_operator(quorum_nums).await.unwrap();

let tx_status = wait_transaction(&http_url, tx_hash).await.unwrap().status();
assert!(tx_status);
}
}
Loading

0 comments on commit 295b462

Please # to comment.