diff --git a/Cargo.lock b/Cargo.lock index 76ef1e4e71..532617fd46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3033,6 +3033,7 @@ dependencies = [ "futures", "hex-literal", "itertools 0.14.0", + "jsonrpc-core", "maplit", "mockall", "observe", @@ -6443,7 +6444,6 @@ dependencies = [ "tracing", "url", "vergen", - "web3", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3f3bbd3f21..6d41e5873d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,6 +106,7 @@ prettyplease = "0.2.37" proc-macro2 = "1.0.103" alloy-sol-macro-input = "1.4.1" alloy-sol-macro-expander = "1.4.1" +jsonrpc-core = "18.0.0" [workspace.lints] clippy.cast_possible_wrap = "deny" diff --git a/crates/driver/Cargo.toml b/crates/driver/Cargo.toml index 1d5b23deab..db9c3a2263 100644 --- a/crates/driver/Cargo.toml +++ b/crates/driver/Cargo.toml @@ -15,7 +15,7 @@ name = "driver" path = "src/main.rs" [dependencies] -alloy = { workspace = true, features = ["sol-types", "provider-txpool-api", "rand"] } +alloy = { workspace = true, features = ["sol-types", "provider-txpool-api", "rand", "provider-anvil-api"] } app-data = { workspace = true } async-trait = { workspace = true } axum = { workspace = true } diff --git a/crates/driver/src/infra/blockchain/contracts.rs b/crates/driver/src/infra/blockchain/contracts.rs index e602ee42e2..deb0aed0c2 100644 --- a/crates/driver/src/infra/blockchain/contracts.rs +++ b/crates/driver/src/infra/blockchain/contracts.rs @@ -8,7 +8,7 @@ use { WETH9, support::Balances, }, - ethrpc::{Web3, alloy::conversions::IntoAlloy}, + ethrpc::Web3, std::collections::HashMap, thiserror::Error, }; @@ -165,22 +165,6 @@ impl Contracts { } } -/// Returns the address of a contract for the specified network, or `None` if -/// there is no known deployment for the contract on that network. -pub fn deployment_address( - contract: ðcontract::Contract, - chain: Chain, -) -> Option { - Some( - contract - .networks - .get(&chain.id().to_string())? - .address - .into_alloy() - .into(), - ) -} - #[derive(Debug, Error)] pub enum Error { #[error("method error: {0:?}")] diff --git a/crates/driver/src/infra/notify/liquidity_sources/mod.rs b/crates/driver/src/infra/notify/liquidity_sources/mod.rs index 2a7c409bf0..43adda3549 100644 --- a/crates/driver/src/infra/notify/liquidity_sources/mod.rs +++ b/crates/driver/src/infra/notify/liquidity_sources/mod.rs @@ -8,14 +8,13 @@ /// need to know as early as possible that their quote will be used for the /// settlement. It is crucial for risk management and leads to better /// pricing. -use futures::FutureExt; pub mod config; pub mod liquorice; pub use config::Config; use { crate::domain::competition::solution::settlement::Settlement, - ethcontract::jsonrpc::futures_util::future::join_all, + futures::{FutureExt, future::join_all}, std::{collections::HashMap, sync::Arc}, }; diff --git a/crates/driver/src/tests/setup/blockchain.rs b/crates/driver/src/tests/setup/blockchain.rs index 9668034b64..1bb886f1ae 100644 --- a/crates/driver/src/tests/setup/blockchain.rs +++ b/crates/driver/src/tests/setup/blockchain.rs @@ -6,6 +6,7 @@ use { }, alloy::{ primitives::{Address, U256}, + providers::{Provider, ext::AnvilApi}, signers::local::{MnemonicBuilder, PrivateKeySigner}, sol_types::SolCall, }, @@ -340,15 +341,17 @@ impl Blockchain { } code }; - let settlement_code = web3 - .eth() - .code(settlement.address().into_legacy(), None) + web3.alloy + .anvil_set_code(vault_relayer, vault_relayer_code.into()) .await - .unwrap() - .0; + .unwrap(); - set_code(&web3, vault_relayer, &vault_relayer_code).await; - set_code(&web3, settlement_address, &settlement_code).await; + // Note: (settlement.address() == authenticator_address) != settlement_address + let settlement_code = web3.alloy.get_code_at(*settlement.address()).await.unwrap(); + web3.alloy + .anvil_set_code(settlement_address, settlement_code) + .await + .unwrap(); settlement = GPv2Settlement::GPv2Settlement::new(settlement_address, web3.alloy.clone()); @@ -980,7 +983,7 @@ impl Drop for Node { /// wait for transactions to be confirmed before proceeding with the test. When /// switching from geth back to hardhat, this function can be removed. pub async fn wait_for(web3: &Web3, fut: impl Future) -> T { - let block = web3.eth().block_number().await.unwrap().as_u64(); + let block = web3.alloy.get_block_number().await.unwrap(); let result = fut.await; wait_for_block(web3, block + 1).await; result @@ -990,7 +993,7 @@ pub async fn wait_for(web3: &Web3, fut: impl Future) -> T { pub async fn wait_for_block(web3: &Web3, block: u64) { tokio::time::timeout(std::time::Duration::from_secs(15), async { loop { - let next_block = web3.eth().block_number().await.unwrap().as_u64(); + let next_block = web3.alloy.get_block_number().await.unwrap(); if next_block >= block { break; } @@ -1000,16 +1003,3 @@ pub async fn wait_for_block(web3: &Web3, block: u64) { .await .expect("timeout while waiting for next block to be mined"); } - -/// Sets code at a specific address for testing. -pub async fn set_code(web3: &Web3, address: eth::Address, code: &[u8]) { - use web3::Transport; - - web3.transport() - .execute( - "anvil_setCode", - vec![json!(address), json!(const_hex::encode_prefixed(code))], - ) - .await - .unwrap(); -} diff --git a/crates/e2e/src/setup/onchain_components/safe.rs b/crates/e2e/src/setup/onchain_components/safe.rs index 954e8c944d..290e9b8e83 100644 --- a/crates/e2e/src/setup/onchain_components/safe.rs +++ b/crates/e2e/src/setup/onchain_components/safe.rs @@ -11,11 +11,7 @@ use { GnosisSafeProxy, GnosisSafeProxyFactory, }, - ethcontract::transaction::TransactionBuilder, - ethrpc::{ - AlloyProvider, - alloy::{CallBuilderExt, conversions::IntoAlloy}, - }, + ethrpc::{AlloyProvider, alloy::CallBuilderExt}, hex_literal::hex, model::{ DomainSeparator, @@ -139,21 +135,6 @@ impl Safe { .unwrap(); } - pub async fn exec_call( - &self, - tx: ethcontract::dyns::DynMethodBuilder, - ) { - let TransactionBuilder { - data, value, to, .. - } = tx.tx; - self.exec_alloy_tx( - to.unwrap().into_alloy(), - value.unwrap_or_default().into_alloy(), - alloy::primitives::Bytes::from(data.unwrap_or_default().0), - ) - .await; - } - pub async fn exec_alloy_call(&self, tx: TransactionRequest) { let to = tx.to.unwrap().into_to().unwrap(); let value = tx.value.unwrap_or_default(); diff --git a/crates/ethrpc/Cargo.toml b/crates/ethrpc/Cargo.toml index 0d22f20865..7c8c4315a2 100644 --- a/crates/ethrpc/Cargo.toml +++ b/crates/ethrpc/Cargo.toml @@ -35,6 +35,7 @@ tracing = { workspace = true } url = { workspace = true } web3 = { workspace = true } mockall = { workspace = true, optional = true } +jsonrpc-core.workspace = true [dev-dependencies] mockall = { workspace = true } diff --git a/crates/ethrpc/src/http.rs b/crates/ethrpc/src/http.rs index 20f110b77f..2f1d89fd54 100644 --- a/crates/ethrpc/src/http.rs +++ b/crates/ethrpc/src/http.rs @@ -1,5 +1,4 @@ use { - ethcontract::jsonrpc as jsonrpc_core, futures::{FutureExt, future::BoxFuture}, jsonrpc_core::types::{Call, Output, Request, Value}, observe::tracing::tracing_headers, diff --git a/crates/ethrpc/src/lib.rs b/crates/ethrpc/src/lib.rs index fe306109d0..5546cdebbf 100644 --- a/crates/ethrpc/src/lib.rs +++ b/crates/ethrpc/src/lib.rs @@ -11,7 +11,7 @@ use { self::{buffered::BufferedTransport, http::HttpTransport}, crate::alloy::MutWallet, ::alloy::providers::DynProvider, - ethcontract::{batch::CallBatch, transport::DynTransport}, + ethcontract::transport::DynTransport, reqwest::{Client, Url}, std::{num::NonZeroUsize, time::Duration}, web3::Transport, @@ -20,7 +20,6 @@ use { pub const MAX_BATCH_SIZE: usize = 100; pub type Web3Transport = DynTransport; -pub type Web3CallBatch = CallBatch; pub type AlloyProvider = DynProvider; /// This is just a thin wrapper around providers (clients communicating diff --git a/crates/shared/src/ethrpc.rs b/crates/shared/src/ethrpc.rs index 2bf9993ba2..d855f0c7af 100644 --- a/crates/shared/src/ethrpc.rs +++ b/crates/shared/src/ethrpc.rs @@ -1,4 +1,4 @@ -pub use ethrpc::{Web3, Web3CallBatch, Web3Transport}; +pub use ethrpc::{Web3, Web3Transport}; use { crate::http_client::HttpClientFactory, reqwest::Url, diff --git a/crates/shared/src/macros.rs b/crates/shared/src/macros.rs index 628612a230..784e7dc728 100644 --- a/crates/shared/src/macros.rs +++ b/crates/shared/src/macros.rs @@ -14,13 +14,6 @@ macro_rules! bfp { }; } -#[macro_export] -macro_rules! bytes { - ($x:literal) => { - ::ethcontract::web3::types::Bytes(::hex_literal::hex!($x).to_vec()) - }; -} - #[macro_export] macro_rules! json_map { ($($key:expr_2021 => $value:expr_2021),* $(,)?) => {{ diff --git a/crates/shared/src/price_estimation/instrumented.rs b/crates/shared/src/price_estimation/instrumented.rs index ec95ab11d8..6a23c4cd22 100644 --- a/crates/shared/src/price_estimation/instrumented.rs +++ b/crates/shared/src/price_estimation/instrumented.rs @@ -6,8 +6,7 @@ use { native::{NativePriceEstimateResult, NativePriceEstimating}, }, alloy::primitives::Address, - ethcontract::jsonrpc::futures_util::future::BoxFuture, - futures::future::FutureExt, + futures::future::{BoxFuture, FutureExt}, prometheus::{HistogramVec, IntCounterVec}, std::{ sync::Arc, diff --git a/crates/shared/src/sources/uniswap_v2/mod.rs b/crates/shared/src/sources/uniswap_v2/mod.rs index 21cc73fa11..8c07616489 100644 --- a/crates/shared/src/sources/uniswap_v2/mod.rs +++ b/crates/shared/src/sources/uniswap_v2/mod.rs @@ -206,7 +206,7 @@ mod tests { token1: Address, expected_pool_address: Address, ) { - let version_ = web3.eth().chain_id().await.unwrap().to_string(); + let version_ = web3.alloy.get_chain_id().await.unwrap().to_string(); assert_eq!(version_, version, "wrong node for test"); let source = UniV2BaselineSourceParameters::from_baseline_source(source, version) .unwrap() @@ -222,7 +222,7 @@ mod tests { #[ignore] async fn baseline_mainnet() { let web3 = ethrpc::Web3::new_from_env(); - let version = web3.eth().chain_id().await.unwrap().to_string(); + let version = web3.alloy.get_chain_id().await.unwrap().to_string(); assert_eq!(version, "1", "test must be run with mainnet node"); let test = |source, token0, token1, expected| { test_baseline_source(&web3, "1", source, token0, token1, expected) @@ -255,7 +255,7 @@ mod tests { #[ignore] async fn baseline_sepolia() { let web3 = ethrpc::Web3::new_from_env(); - let version = web3.eth().chain_id().await.unwrap().to_string(); + let version = web3.alloy.get_chain_id().await.unwrap().to_string(); assert_eq!(version, "11155111", "test must be run with mainnet node"); let test = |source, token0, token1, expected| { test_baseline_source(&web3, "11155111", source, token0, token1, expected) @@ -275,7 +275,7 @@ mod tests { #[ignore] async fn baseline_xdai() { let web3 = ethrpc::Web3::new_from_env(); - let version = web3.eth().chain_id().await.unwrap().to_string(); + let version = web3.alloy.get_chain_id().await.unwrap().to_string(); assert_eq!(version, "100", "test must be run with xdai node"); let test = |source, token0, token1, expected| { test_baseline_source(&web3, "100", source, token0, token1, expected) diff --git a/crates/shared/src/sources/uniswap_v2/pair_provider.rs b/crates/shared/src/sources/uniswap_v2/pair_provider.rs index 7788195e69..b82cb1e754 100644 --- a/crates/shared/src/sources/uniswap_v2/pair_provider.rs +++ b/crates/shared/src/sources/uniswap_v2/pair_provider.rs @@ -1,4 +1,7 @@ -use {alloy::primitives::Address, model::TokenPair, web3::signing::keccak256}; +use { + alloy::primitives::{Address, keccak256}, + model::TokenPair, +}; #[derive(Clone, Copy, Debug)] pub struct PairProvider { @@ -15,7 +18,7 @@ impl PairProvider { let mut buffer = [0u8; 40]; buffer[0..20].copy_from_slice(token0.as_slice()); buffer[20..40].copy_from_slice(token1.as_slice()); - keccak256(&buffer) + keccak256(buffer) }; create2_target_address(self.factory, &salt, &self.init_code_digest) } @@ -30,7 +33,7 @@ fn create2_target_address( preimage[1..21].copy_from_slice(creator.as_slice()); preimage[21..53].copy_from_slice(salt); preimage[53..85].copy_from_slice(init_code_digest); - Address::from_slice(&keccak256(&preimage)[12..]) + Address::from_slice(&keccak256(preimage)[12..]) } #[cfg(test)] diff --git a/crates/solvers/Cargo.toml b/crates/solvers/Cargo.toml index 82a416785e..25c2b32507 100644 --- a/crates/solvers/Cargo.toml +++ b/crates/solvers/Cargo.toml @@ -42,7 +42,6 @@ toml = { workspace = true } tower = { workspace = true } tower-http = { workspace = true, features = ["limit", "trace"] } url = { workspace = true, features = ["serde"] } -web3 = { workspace = true } # TODO Once solvers are ported and E2E tests set up, slowly migrate code and # remove/re-evaluate these dependencies. diff --git a/crates/solvers/src/domain/eth/mod.rs b/crates/solvers/src/domain/eth/mod.rs index 08896eacc1..677e2a2076 100644 --- a/crates/solvers/src/domain/eth/mod.rs +++ b/crates/solvers/src/domain/eth/mod.rs @@ -1,5 +1,5 @@ pub use alloy::primitives::{Address, B256, U256}; -use {crate::util::bytes::Bytes, derive_more::From, web3::types::AccessList}; +use {crate::util::bytes::Bytes, alloy::rpc::types::AccessList, derive_more::From}; /// A contract address. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]