Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Oct 30, 2024
1 parent 51fa5cc commit ef30de3
Show file tree
Hide file tree
Showing 38 changed files with 197 additions and 199 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/autopilot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bytes-hex = { path = "../bytes-hex" }
anyhow = { workspace = true }
async-trait = { workspace = true }
bigdecimal = { workspace = true }
chain = { path = "../chain" }
chrono = { workspace = true }
clap = { workspace = true }
contracts = { path = "../contracts" }
Expand All @@ -40,7 +41,6 @@ itertools = { workspace = true }
maplit = { workspace = true }
mimalloc = { workspace = true }
model = { path = "../model" }
network = { path = "../network" }
num = { workspace = true }
number = { path = "../number" }
order-validation = { path = "../order-validation" }
Expand Down
10 changes: 5 additions & 5 deletions crates/autopilot/src/domain/settlement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod auction;
mod observer;
mod trade;
mod transaction;
use network::Network;
use chain::Chain;
pub use {auction::Auction, observer::Observer, trade::Trade, transaction::Transaction};

/// A settled transaction together with the `Auction`, for which it was executed
Expand Down Expand Up @@ -107,11 +107,11 @@ impl Settlement {
pub async fn new(
settled: Transaction,
persistence: &infra::Persistence,
network: &Network,
chain: &Chain,
) -> Result<Self, Error> {
let auction = persistence.get_auction(settled.auction_id).await?;

if settled.block > auction.block + max_settlement_age(network) {
if settled.block > auction.block + max_settlement_age(chain) {
// A settled transaction references a VERY old auction.
//
// A hacky way to detect processing of production settlements in the staging
Expand Down Expand Up @@ -143,9 +143,9 @@ impl Settlement {
/// settlement from another environment.
///
/// Currently set to ~6h
fn max_settlement_age(network: &Network) -> u64 {
fn max_settlement_age(chain: &Chain) -> u64 {
const TARGET_AGE: u64 = 6 * 60 * 60 * 1000; // 6h in ms
network.blocks_in(TARGET_AGE).round() as u64
chain.blocks_in(TARGET_AGE).round() as u64
}

#[derive(Debug, thiserror::Error)]
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/domain/settlement/observer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Observer {
let settlement = match settlement::Settlement::new(
transaction,
&self.persistence,
self.eth.network(),
self.eth.chain(),
)
.await
{
Expand Down
6 changes: 3 additions & 3 deletions crates/autopilot/src/infra/blockchain/authenticator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use {
domain::{self, eth},
infra::blockchain::contracts::{deployment_address, Contracts},
},
chain::Chain,
ethcontract::{dyns::DynWeb3, GasPrice},
network::Network,
};

#[allow(dead_code)]
Expand All @@ -23,13 +23,13 @@ impl Manager {
/// Creates an authenticator which can remove solvers from the allow-list
pub async fn new(
web3: DynWeb3,
network: &Network,
chain: &Chain,
contracts: Contracts,
authenticator_pk: eth::H256,
) -> Self {
let authenticator_role = contracts::Roles::at(
&web3,
deployment_address(contracts::Roles::raw_contract(), network).expect("roles address"),
deployment_address(contracts::Roles::raw_contract(), chain).expect("roles address"),
);

Self {
Expand Down
14 changes: 7 additions & 7 deletions crates/autopilot/src/infra/blockchain/contracts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use {crate::domain, ethcontract::dyns::DynWeb3, network::Network, primitive_types::H160};
use {crate::domain, chain::Chain, ethcontract::dyns::DynWeb3, primitive_types::H160};

#[derive(Debug, Clone)]
pub struct Contracts {
Expand All @@ -20,10 +20,10 @@ pub struct Addresses {
}

impl Contracts {
pub async fn new(web3: &DynWeb3, network: &Network, addresses: Addresses) -> Self {
pub async fn new(web3: &DynWeb3, chain: &Chain, addresses: Addresses) -> Self {
let address_for = |contract: &ethcontract::Contract, address: Option<H160>| {
address
.or_else(|| deployment_address(contract, network))
.or_else(|| deployment_address(contract, chain))
.unwrap()
};

Expand Down Expand Up @@ -96,11 +96,11 @@ 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, network: &Network) -> Option<H160> {
/// Returns the address of a contract for the specified chain, or `None` if
/// there is no known deployment for the contract on that chain.
pub fn deployment_address(contract: &ethcontract::Contract, chain: &Chain) -> Option<H160> {
contract
.networks
.get(&network.chain_id().to_string())
.get(&chain.id().to_string())
.map(|network| network.address)
}
28 changes: 14 additions & 14 deletions crates/autopilot/src/infra/blockchain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use {
self::contracts::Contracts,
crate::{boundary, domain::eth},
chain::Chain,
ethcontract::dyns::DynWeb3,
ethrpc::block_stream::CurrentBlockWatcher,
network::Network,
primitive_types::U256,
std::time::Duration,
thiserror::Error,
Expand All @@ -16,7 +16,7 @@ pub mod contracts;
/// An Ethereum RPC connection.
pub struct Rpc {
web3: DynWeb3,
network: Network,
chain: Chain,
url: Url,
}

Expand All @@ -28,19 +28,19 @@ impl Rpc {
ethrpc_args: &shared::ethrpc::Arguments,
) -> Result<Self, Error> {
let web3 = boundary::web3_client(url, ethrpc_args);
let network =
Network::try_from(web3.eth().chain_id().await?).map_err(|_| Error::UnsupportedChain)?;
let chain =
Chain::try_from(web3.eth().chain_id().await?).map_err(|_| Error::UnsupportedChain)?;

Ok(Self {
web3,
network,
chain,
url: url.clone(),
})
}

/// Returns the chain id for the RPC connection.
pub fn network(&self) -> Network {
self.network
/// Returns the chain for the RPC connection.
pub fn chain(&self) -> Chain {
self.chain
}

/// Returns a reference to the underlying web3 client.
Expand All @@ -58,7 +58,7 @@ impl Rpc {
#[derive(Clone)]
pub struct Ethereum {
web3: DynWeb3,
network: Network,
chain: Chain,
current_block: CurrentBlockWatcher,
contracts: Contracts,
}
Expand All @@ -72,25 +72,25 @@ impl Ethereum {
/// any initialization error.
pub async fn new(
web3: DynWeb3,
network: &Network,
chain: &Chain,
url: Url,
addresses: contracts::Addresses,
poll_interval: Duration,
) -> Self {
let contracts = Contracts::new(&web3, network, addresses).await;
let contracts = Contracts::new(&web3, chain, addresses).await;

Self {
current_block: ethrpc::block_stream::current_block_stream(url, poll_interval)
.await
.expect("couldn't initialize current block stream"),
web3,
network: *network,
chain: *chain,
contracts,
}
}

pub fn network(&self) -> &Network {
&self.network
pub fn chain(&self) -> &Chain {
&self.chain
}

/// Returns a stream that monitors the block chain to inform about the
Expand Down
16 changes: 8 additions & 8 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use {
shadow,
solvable_orders::SolvableOrdersCache,
},
chain::Chain,
clap::Parser,
contracts::{BalancerV2Vault, IUniswapV3Factory},
ethcontract::{dyns::DynWeb3, errors::DeployError, BlockNumber},
ethrpc::block_stream::block_number_to_block_number_hash,
futures::StreamExt,
model::DomainSeparator,
network::Network,
shared::{
account_balances,
bad_token::{
Expand Down Expand Up @@ -94,12 +94,12 @@ async fn ethrpc(url: &Url, ethrpc_args: &shared::ethrpc::Arguments) -> infra::bl

async fn ethereum(
web3: DynWeb3,
network: &Network,
chain: &Chain,
url: Url,
contracts: infra::blockchain::contracts::Addresses,
poll_interval: Duration,
) -> infra::Ethereum {
infra::Ethereum::new(web3, network, url, contracts, poll_interval).await
infra::Ethereum::new(web3, chain, url, contracts, poll_interval).await
}

pub async fn start(args: impl Iterator<Item = String>) {
Expand Down Expand Up @@ -157,7 +157,7 @@ pub async fn run(args: Arguments) {
}

let ethrpc = ethrpc(&args.shared.node_url, &args.shared.ethrpc).await;
let chain = ethrpc.network();
let chain = ethrpc.chain();
let web3 = ethrpc.web3().clone();
let url = ethrpc.url().clone();
let contracts = infra::blockchain::contracts::Addresses {
Expand Down Expand Up @@ -198,7 +198,7 @@ pub async fn run(args: Arguments) {
other => Some(other.unwrap()),
};

let network = Network::try_from(chain_id).unwrap();
let chain = Chain::try_from(chain_id).unwrap();

let signature_validator = signature_validator::validator(
&web3,
Expand Down Expand Up @@ -233,7 +233,7 @@ pub async fn run(args: Arguments) {
.shared
.baseline_sources
.clone()
.unwrap_or_else(|| shared::sources::defaults_for_network(&network));
.unwrap_or_else(|| shared::sources::defaults_for_network(&chain));
tracing::info!(?baseline_sources, "using baseline sources");
let univ2_sources = baseline_sources
.iter()
Expand Down Expand Up @@ -261,7 +261,7 @@ pub async fn run(args: Arguments) {
let finder = token_owner_finder::init(
&args.token_owner_finder,
web3.clone(),
&network,
&chain,
&http_factory,
&pair_providers,
vault.as_ref(),
Expand Down Expand Up @@ -312,7 +312,7 @@ pub async fn run(args: Arguments) {
factory::Network {
web3: web3.clone(),
simulation_web3,
network,
chain,
native_token: eth.contracts().weth().address(),
settlement: eth.contracts().settlement().address(),
authenticator: eth
Expand Down
2 changes: 1 addition & 1 deletion crates/network/Cargo.toml → crates/chain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "network"
name = "chain"
version = "0.1.0"
authors = ["Cow Protocol Developers <dev@cow.fi>"]
edition = "2021"
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ef30de3

Please sign in to comment.