Skip to content
Merged

L2 #5

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,6 @@ jobs:
- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

cargo-fix:
name: cargo fix
runs-on: ubuntu-latest
steps:
- name: Check-Out
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: stable

- uses: Swatinem/rust-cache@v2
with:
key: cargo-fix
cache-on-failure: true

- name: cargo clippy --workspace --all-targets --all-features -- -D warnings
run: |
# Run cargo fix on the project
cargo clippy --workspace --all-targets --all-features -- -D warnings

# Check for local git changes
if ! git diff --exit-code; then
echo "There are local changes after running 'cargo clippy --workspace --all-targets --all-features' ❌"
exit 1
else
echo "No changes detected after running 'cargo clippy --workspace --all-targets --all-features' ✅"
fi

cargo-test:
name: cargo test
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
.vscode/
.DS_Store
.env
.env
.claude
4 changes: 3 additions & 1 deletion Cargo.lock

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

8 changes: 4 additions & 4 deletions crates/eth-network-exts/src/impls/base_mainnet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::marker::PhantomData;

use op_alloy_network::Optimism;
use reth_optimism_node::OpNode;

use crate::{AllExtensions, EthNetworkExt};

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct BaseMainnetExt<Extension = ()>(Extension)
where
Extension: AllExtensions;
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct BaseMainnetExt<Extension = ()>(PhantomData<Extension>);

impl<Extension: AllExtensions> EthNetworkExt for BaseMainnetExt<Extension> {
type AlloyNetwork = Optimism;
Expand Down
8 changes: 4 additions & 4 deletions crates/eth-network-exts/src/impls/mainnet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::marker::PhantomData;

use alloy_network::Ethereum;
use reth_node_ethereum::EthereumNode;

use crate::{AllExtensions, EthNetworkExt};

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct MainnetExt<Extension = ()>(Extension)
where
Extension: AllExtensions;
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct MainnetExt<Extension = ()>(PhantomData<Extension>);

impl<Extension: AllExtensions> EthNetworkExt for MainnetExt<Extension> {
type AlloyNetwork = Ethereum;
Expand Down
8 changes: 4 additions & 4 deletions crates/eth-network-exts/src/impls/sepolia_testnet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::marker::PhantomData;

use alloy_network::Ethereum;
use reth_node_ethereum::EthereumNode;

use crate::{AllExtensions, EthNetworkExt};

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct SepoliaTestnetExt<Extension = ()>(Extension)
where
Extension: AllExtensions;
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct SepoliaTestnetExt<Extension = ()>(PhantomData<Extension>);

impl<Extension: AllExtensions> EthNetworkExt for SepoliaTestnetExt<Extension> {
type AlloyNetwork = Ethereum;
Expand Down
8 changes: 4 additions & 4 deletions crates/eth-network-exts/src/impls/unichain_mainnet.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::marker::PhantomData;

use op_alloy_network::Optimism;
use reth_optimism_node::OpNode;

use crate::{AllExtensions, EthNetworkExt};

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct UnichainMainnetExt<Extension = ()>(Extension)
where
Extension: AllExtensions;
#[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct UnichainMainnetExt<Extension = ()>(PhantomData<Extension>);

impl<Extension: AllExtensions> EthNetworkExt for UnichainMainnetExt<Extension> {
type AlloyNetwork = Optimism;
Expand Down
2 changes: 1 addition & 1 deletion crates/eth-network-exts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod impls;
pub use impls::*;

pub trait EthNetworkExt: Send + Sync {
type AlloyNetwork: alloy_network::Network;
type AlloyNetwork: alloy_network::Network + Unpin;
type RethNode: reth_node_types::NodeTypes;
/// an arbitrary type extension
type TypeExt;
Expand Down
3 changes: 2 additions & 1 deletion crates/lib-reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ alloy-rpc-types = { workspace = true, default-features = false, features = [
"eth",
] }
alloy-primitives = { workspace = true, default-features = false }
alloy-eips = { workspace = true, optional = true }
op-alloy-network = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, optional = true }

Expand Down Expand Up @@ -126,6 +127,6 @@ reth-libmdbx = [
"dep:reth-storage-api",
]

uniswap-storage = ["dep:uniswap-storage"]
uniswap-storage = ["dep:uniswap-storage", "dep:alloy-eips"]

ci = []
1 change: 1 addition & 0 deletions crates/lib-reth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use regular_reth::*;
mod regular_reth {
pub use reth_chainspec::*;
pub use reth_node_ethereum::EthereumNode;
pub use reth_node_types::NodeTypes;
pub use reth_rpc_eth_api::*;
pub use reth_storage_api::*;
pub use revm::*;
Expand Down
15 changes: 4 additions & 11 deletions crates/lib-reth/src/reth_libmdbx/node_types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::sync::Arc;

#[cfg(feature = "revm")]
use alloy_eips::BlockId;
use alloy_provider::{IpcConnect, RootProvider, WsConnect, builder};
use eth_network_exts::EthNetworkExt;
use reth_node_types::NodeTypes;
Expand All @@ -9,8 +11,6 @@ use reth_provider::{
use reth_rpc_eth_api::{EthApiTypes, FullEthApiServer, RpcNodeCore, helpers::FullEthApi};
use reth_tasks::TaskSpawner;

#[cfg(feature = "revm")]
use crate::traits::BlockNumberOrHash;
use crate::{reth_libmdbx::DbConfig, traits::EthStream};

pub mod node;
Expand Down Expand Up @@ -126,17 +126,10 @@ where
{
type InnerDb = crate::traits::reth_revm_utils::RethLibmdbxDatabaseRef;

fn make_inner_db<T: Into<BlockNumberOrHash>>(&self, block: T) -> eyre::Result<Self::InnerDb> {
fn make_inner_db(&self, block: BlockId) -> eyre::Result<Self::InnerDb> {
use reth_provider::StateProviderFactory;

let block: BlockNumberOrHash = block.into();

let state_provider = match block {
BlockNumberOrHash::Number(num) => self
.eth_db_provider()
.state_by_block_number_or_tag(num.into())?,
BlockNumberOrHash::Hash(hash) => self.eth_db_provider().state_by_block_hash(hash)?
};
let state_provider = self.eth_db_provider().state_by_block_id(block)?;

let this = reth_revm::database::StateProviderDatabase::new(state_provider);
Ok(crate::traits::reth_revm_utils::RethLibmdbxDatabaseRef::new(this))
Expand Down
13 changes: 5 additions & 8 deletions crates/lib-reth/src/traits/reth_revm_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl From<eyre::ErrReport> for RevmUtilError {

#[cfg(feature = "uniswap-storage")]
mod _uniswap_storage {
use alloy_eips::BlockId;
use alloy_primitives::{Address, StorageKey, StorageValue};
use eth_network_exts::EthNetworkExt;
use reth_provider::StateProvider;
Expand All @@ -108,7 +109,8 @@ mod _uniswap_storage {

#[async_trait::async_trait]
impl StorageSlotFetcher for RethLibmdbxDatabaseRef {
async fn storage_at(&self, address: Address, key: StorageKey, _: Option<u64>) -> eyre::Result<StorageValue> {
async fn storage_at(&self, address: Address, key: StorageKey, block_id: BlockId) -> eyre::Result<StorageValue> {
let _ = block_id;
let db = self.0.lock().map_err(|e| eyre::eyre!("{e}"))?;
Ok(db.storage(address, key)?.unwrap_or_default())
}
Expand All @@ -119,15 +121,10 @@ mod _uniswap_storage {
where
Ext::RethNode: NodeClientSpec
{
async fn storage_at(
&self,
address: Address,
key: StorageKey,
block_number: Option<u64>
) -> eyre::Result<StorageValue> {
async fn storage_at(&self, address: Address, key: StorageKey, block_id: BlockId) -> eyre::Result<StorageValue> {
Ok(self
.eth_api()
.storage_at(address, key.into(), block_number.map(Into::into))
.storage_at(address, key.into(), Some(block_id))
.await?
.into())
}
Expand Down
30 changes: 6 additions & 24 deletions crates/lib-reth/src/traits/revm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::B256;
use alloy_eips::BlockId;
use revm::{
Context, DatabaseRef, MainBuilder, MainContext,
context::{BlockEnv, CfgEnv, Evm, TxEnv},
Expand All @@ -15,39 +15,21 @@ pub type RevmEvm<DB> = Evm<
EthFrame
>;

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum BlockNumberOrHash {
Number(u64),
Hash(B256)
}

impl From<u64> for BlockNumberOrHash {
fn from(value: u64) -> Self {
Self::Number(value)
}
}

impl From<B256> for BlockNumberOrHash {
fn from(value: B256) -> Self {
Self::Hash(value)
}
}

/// revm utils
pub trait EthRevm {
type InnerDb: DatabaseRef;

/// `makes the inner database fetcher`
fn make_inner_db<T: Into<BlockNumberOrHash>>(&self, block: T) -> eyre::Result<Self::InnerDb>;
fn make_inner_db(&self, block_id: BlockId) -> eyre::Result<Self::InnerDb>;

/// `makes a new cache db`
fn make_cache_db<T: Into<BlockNumberOrHash>>(&self, block: T) -> eyre::Result<CacheDB<Self::InnerDb>> {
Ok(CacheDB::new(self.make_inner_db(block)?))
fn make_cache_db(&self, block_id: BlockId) -> eyre::Result<CacheDB<Self::InnerDb>> {
Ok(CacheDB::new(self.make_inner_db(block_id)?))
}

/// `makes a new cache db`
fn make_empty_evm<T: Into<BlockNumberOrHash>>(&self, block: T) -> eyre::Result<RevmEvm<CacheDB<Self::InnerDb>>> {
let cache = self.make_cache_db(block)?;
fn make_empty_evm(&self, block_id: BlockId) -> eyre::Result<RevmEvm<CacheDB<Self::InnerDb>>> {
let cache = self.make_cache_db(block_id)?;
let evm = Context::mainnet().with_db(cache).build_mainnet();
Ok(evm)
}
Expand Down
23 changes: 14 additions & 9 deletions crates/uniswap-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,41 @@ alloy-network.workspace = true

revm-database = { workspace = true, optional = true, features = ["alloydb"] }
reth-provider = { workspace = true, optional = true }
reth-optimism-rpc = { workspace = true, optional = true }
reth-rpc = { workspace = true, optional = true }
reth-rpc-convert = { workspace = true, optional = true }
eth-network-exts.workspace = true

futures.workspace = true
serde = { version = "1", features = ["derive"] }
auto_impl = "1.3"
eyre = "0.6.12"
auto_impl.workspace = true
eyre.workspace = true
itertools = "0.14"
async-trait = "0"
async-trait.workspace = true


[dev-dependencies]
alloy-provider = { version = "1.1.3", default-features = false, features = [
alloy-provider = { workspace = true, default-features = false, features = [
"pubsub",
"ws",
] }
tokio = { version = "1", features = ["full"] }
tokio = { workspace = true, features = ["full"] }
dotenv = "0.15"
op-alloy-network = { version = "0.23.1", default-features = false }

[features]
default = ["full", "revm"]
full = ["v4", "v3", "angstrom"]
default = ["v4", "v3", "l1-angstrom", "revm"]
full = ["v4", "v3", "l1-angstrom", "l2-angstrom"]

v4 = []
v3 = []
angstrom = []
l1-angstrom = ["v4"]
l2-angstrom = ["v4"]

revm = ["dep:revm-database"]
local-reth = [
"dep:revm-database",
"dep:reth-provider",
"dep:reth-rpc",
"dep:reth-rpc-convert",
"dep:reth-optimism-rpc",
]
Loading