Skip to content

Commit

Permalink
anvil_constants : helper functions to extract anvil eigen layer contr…
Browse files Browse the repository at this point in the history
…acts easily
  • Loading branch information
supernovahs committed Jun 20, 2024
1 parent c67ddd0 commit 9df665c
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ members = [ "crates/chainio/clients/avsregistry/",
"examples/info-operator-service/",
"testing/testing-utils/",
"examples/avsregistry-read",
"examples/avsregistry-write"
"examples/avsregistry-write",
"examples/anvil-utils"
]

resolver = "2"
Expand Down Expand Up @@ -117,4 +118,5 @@ alloy-rpc-client = {git = "https://github.com/alloy-rs/alloy", rev = "cc68b93"}

# examples
avsregistry-read = {path = "examples/avsregistry-read"}
avsregistry-write = {path = "examples/avsregistry-write"}
avsregistry-write = {path = "examples/avsregistry-write"}
anvil-utils = {path = "examples/anvil-utils"}
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


__CONTRACTS__: ##

start-anvil-with-contracts-deployed: ##
./crates/contracts/anvil/start_anvil_chain_with_el_and_avs_deployed.sh


deploy-contracts-to-anvil-and-save-state: ##
./crates/contracts/anvil/deploy_contracts_save_anvil_state.sh

Large diffs are not rendered by default.

Empty file modified crates/contracts/anvil/deploy_contracts_save_anvil_state.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion crates/contracts/anvil/start_anvil_chain_with_el_and_avs_deployed.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set +a

# start an anvil instance in the background that has eigenlayer contracts deployed
# we start anvil in the background so that we can run the below script
start_anvil_docker $anvil_dir/contracts-deployed-anvil-state.json ""
start_anvil_docker $anvil_dir/contracts_deployed_anvil_state.json ""

cd $root_dir/contracts
# we need to restart the anvil chain at the correct block, otherwise the indexRegistry has a quorumUpdate at the block number
Expand Down
141 changes: 141 additions & 0 deletions crates/contracts/bindings/utils/json/ContractsRegistry.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions crates/utils/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ sol!(
ECDSAStakeRegistry,
"../../crates/contracts/bindings/utils/json/ECDSAStakeRegistry.json"
);

sol!(
#[allow(missing_docs)]
#[sol(rpc)]
ContractsRegistry,
"../../crates/contracts/bindings/utils/json/ContractsRegistry.json"
);
20 changes: 20 additions & 0 deletions examples/anvil-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "examples-anvil-utils"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true
license-file.workspace = true
authors.workspace = true


[lints]
workspace = true

[dependencies]
alloy-primitives.workspace = true
eyre.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

eigen-client-avsregistry.workspace = true
eigen-testing-utils.workspace = true
16 changes: 16 additions & 0 deletions examples/anvil-utils/examples/get_contracts_from_registry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use eigen_testing_utils::anvil_constants::{
get_delegation_manager_address, get_erc20_mock_strategy, get_operator_state_retriever_address,
get_registry_coordinator_address, get_service_manager_address, get_strategy_manager_address,
};
use eyre::Result;

#[tokio::main]
pub async fn main() -> Result<()> {
get_service_manager_address().await;
get_registry_coordinator_address().await;
get_operator_state_retriever_address().await;
get_delegation_manager_address().await;
get_strategy_manager_address().await;
get_erc20_mock_strategy().await;
Ok(())
}
7 changes: 6 additions & 1 deletion testing/testing-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ repository.workspace = true
workspace = true

[dependencies]
alloy-primitives.workspace = true
alloy-primitives.workspace = true
eigen-utils.workspace = true
once_cell.workspace = true
alloy-provider.workspace = true
alloy-transport-http.workspace = true
alloy-network.workspace = true
109 changes: 109 additions & 0 deletions testing/testing-utils/src/anvil_constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
use alloy_network::Ethereum;
use alloy_primitives::{address, Address, U256};
use alloy_provider::{
fillers::{ChainIdFiller, FillProvider, GasFiller, JoinFill, NonceFiller},
RootProvider,
};
use alloy_transport_http::{Client, Http};
use eigen_utils::{
binding::ContractsRegistry::{self, contractNamesReturn},
get_provider,
};
use once_cell::sync::Lazy;

pub const CONTRACTS_REGISTRY: Address = address!("5FbDB2315678afecb367f032d93F642f64180aa3");
pub static ANVIL_RPC_URL: Lazy<
FillProvider<
JoinFill<
JoinFill<JoinFill<alloy_provider::Identity, GasFiller>, NonceFiller>,
ChainIdFiller,
>,
RootProvider<Http<Client>>,
Http<Client>,
Ethereum,
>,
> = Lazy::new(|| get_provider(&"http://localhost:8545".to_string()));

pub async fn get_service_manager_address() {
let contracts_registry = ContractsRegistry::new(CONTRACTS_REGISTRY, (*ANVIL_RPC_URL).clone());

let val = contracts_registry
.contractNames(U256::from(0))
.call()
.await
.unwrap();

let contractNamesReturn { _0: first_name } = val;

println!("contract name : {:?}", first_name);
}

pub async fn get_registry_coordinator_address() {
let contracts_registry = ContractsRegistry::new(CONTRACTS_REGISTRY, (*ANVIL_RPC_URL).clone());

let val = contracts_registry
.contractNames(U256::from(1))
.call()
.await
.unwrap();

let contractNamesReturn { _0: first_name } = val;

println!("contract name : {:?}", first_name);
}

pub async fn get_operator_state_retriever_address() {
let contracts_registry = ContractsRegistry::new(CONTRACTS_REGISTRY, (*ANVIL_RPC_URL).clone());

let val = contracts_registry
.contractNames(U256::from(2))
.call()
.await
.unwrap();

let contractNamesReturn { _0: first_name } = val;

println!("contract name : {:?}", first_name);
}

pub async fn get_delegation_manager_address() {
let contracts_registry = ContractsRegistry::new(CONTRACTS_REGISTRY, (*ANVIL_RPC_URL).clone());

let val = contracts_registry
.contractNames(U256::from(3))
.call()
.await
.unwrap();

let contractNamesReturn { _0: first_name } = val;

println!("contract name : {:?}", first_name);
}

pub async fn get_strategy_manager_address() {
let contracts_registry = ContractsRegistry::new(CONTRACTS_REGISTRY, (*ANVIL_RPC_URL).clone());

let val = contracts_registry
.contractNames(U256::from(4))
.call()
.await
.unwrap();

let contractNamesReturn { _0: first_name } = val;

println!("contract name : {:?}", first_name);
}

pub async fn get_erc20_mock_strategy() {
let contracts_registry = ContractsRegistry::new(CONTRACTS_REGISTRY, (*ANVIL_RPC_URL).clone());

let val = contracts_registry
.contractNames(U256::from(5))
.call()
.await
.unwrap();

let contractNamesReturn { _0: first_name } = val;

println!("contract name : {:?}", first_name);
}
3 changes: 3 additions & 0 deletions testing/testing-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ pub mod mainnet_constants;

/// Holesky EigenLayer contract m2 compatible constants.
pub mod m2_holesky_constants;

/// Anvil constants
pub mod anvil_constants;

0 comments on commit 9df665c

Please sign in to comment.