Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion crates/driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
18 changes: 1 addition & 17 deletions crates/driver/src/infra/blockchain/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
WETH9,
support::Balances,
},
ethrpc::{Web3, alloy::conversions::IntoAlloy},
ethrpc::Web3,
std::collections::HashMap,
thiserror::Error,
};
Expand Down Expand Up @@ -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: &ethcontract::Contract,
chain: Chain,
) -> Option<eth::ContractAddress> {
Some(
contract
.networks
.get(&chain.id().to_string())?
.address
.into_alloy()
.into(),
)
}

#[derive(Debug, Error)]
pub enum Error {
#[error("method error: {0:?}")]
Expand Down
3 changes: 1 addition & 2 deletions crates/driver/src/infra/notify/liquidity_sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down
34 changes: 12 additions & 22 deletions crates/driver/src/tests/setup/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
},
alloy::{
primitives::{Address, U256},
providers::{Provider, ext::AnvilApi},
signers::local::{MnemonicBuilder, PrivateKeySigner},
sol_types::SolCall,
},
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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<T>(web3: &Web3, fut: impl Future<Output = T>) -> 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
Expand All @@ -990,7 +993,7 @@ pub async fn wait_for<T>(web3: &Web3, fut: impl Future<Output = T>) -> 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;
}
Expand All @@ -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();
}
21 changes: 1 addition & 20 deletions crates/e2e/src/setup/onchain_components/safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -139,21 +135,6 @@ impl Safe {
.unwrap();
}

pub async fn exec_call<T: ethcontract::tokens::Tokenize>(
&self,
tx: ethcontract::dyns::DynMethodBuilder<T>,
) {
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();
Expand Down
1 change: 1 addition & 0 deletions crates/ethrpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tracing = { workspace = true }
url = { workspace = true }
web3 = { workspace = true }
mockall = { workspace = true, optional = true }
jsonrpc-core.workspace = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason this doesn't use the same formatting as every other dependency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why do we need this dependency here in the first place? I don't see this being used anywhere in the PR. Is this similar to the feature unification issue where building some crates required them to be built together with some other crates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here: https://github.com/cowprotocol/services/pull/3981/changes#diff-f48c389d126b8afd133990245b459039d7bbdc83c073d5114471ea5f937ecc33L4

About the formatting, I added it using cargo add so it came out like that. IMO we should use a formatter for the TOMLs too


[dev-dependencies]
mockall = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/ethrpc/src/http.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 1 addition & 2 deletions crates/ethrpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,7 +20,6 @@ use {
pub const MAX_BATCH_SIZE: usize = 100;

pub type Web3Transport = DynTransport;
pub type Web3CallBatch = CallBatch<Web3Transport>;
pub type AlloyProvider = DynProvider;

/// This is just a thin wrapper around providers (clients communicating
Expand Down
2 changes: 1 addition & 1 deletion crates/shared/src/ethrpc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use ethrpc::{Web3, Web3CallBatch, Web3Transport};
pub use ethrpc::{Web3, Web3Transport};
use {
crate::http_client::HttpClientFactory,
reqwest::Url,
Expand Down
7 changes: 0 additions & 7 deletions crates/shared/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),* $(,)?) => {{
Expand Down
3 changes: 1 addition & 2 deletions crates/shared/src/price_estimation/instrumented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions crates/shared/src/sources/uniswap_v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions crates/shared/src/sources/uniswap_v2/pair_provider.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}
Expand All @@ -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)]
Expand Down
1 change: 0 additions & 1 deletion crates/solvers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/solvers/src/domain/eth/mod.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
Loading