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 c342c23
Show file tree
Hide file tree
Showing 46 changed files with 217 additions and 226 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
10 changes: 5 additions & 5 deletions crates/autopilot/src/domain/settlement/trade/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Trade {
Ok(price.in_eth(surplus.amount))
}

/// Total fee (protocol fee + network fee). Equal to a surplus difference
/// Total fee (protocol fee + chain fee). Equal to a surplus difference
/// before and after applying the fees.
pub fn fee_in_ether(&self, prices: &auction::Prices) -> Result<eth::Ether, Error> {
let fee = self.fee()?;
Expand All @@ -132,14 +132,14 @@ impl Trade {
Ok(fee_in_sell_token)
}

/// Total fee (protocol fee + network fee). Equal to a surplus difference
/// Total fee (protocol fee + chain fee). Equal to a surplus difference
/// before and after applying the fees.
pub fn fee_in_sell_token(&self) -> Result<eth::SellTokenAmount, Error> {
let fee = self.fee()?;
self.fee_into_sell_token(fee.amount)
}

/// Total fee (protocol fee + network fee). Equal to a surplus difference
/// Total fee (protocol fee + chain fee). Equal to a surplus difference
/// before and after applying the fees.
///
/// Denominated in SURPLUS token
Expand Down Expand Up @@ -301,7 +301,7 @@ impl Trade {
}

/// Uses custom prices to calculate the surplus after the protocol fee and
/// network fee are applied.
/// chain fee are applied.
fn surplus_over_limit_price(&self) -> Result<eth::Asset, error::Math> {
let limit_price = PriceLimits {
sell: self.sell.amount,
Expand All @@ -311,7 +311,7 @@ impl Trade {
}

/// Uses uniform prices to calculate the surplus as if the protocol fee and
/// network fee are not applied.
/// chain fee are not applied.
fn surplus_over_limit_price_before_fee(&self) -> Result<eth::Asset, error::Math> {
let limit_price = PriceLimits {
sell: self.sell.amount,
Expand Down
2 changes: 1 addition & 1 deletion crates/autopilot/src/domain/settlement/trade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub struct Jit {
/// trade.
#[derive(Debug, Clone)]
pub struct FeeBreakdown {
/// Total fee the trade was charged (network fee + protocol fee)
/// Total fee the trade was charged (chain fee + protocol fee)
// TODO: express in surplus token
pub total: eth::SellTokenAmount,
/// Breakdown of protocol fees.
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)
}
26 changes: 13 additions & 13 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
pub fn network(&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 network(&self) -> &Chain {
&self.chain
}

/// Returns a stream that monitors the block chain to inform about the
Expand Down
Loading

0 comments on commit c342c23

Please sign in to comment.