Skip to content

Commit

Permalink
[EASY] Delete dead code (#3146)
Browse files Browse the repository at this point in the history
# Description
I was curious about our test coverage and noticed that the generated
report can be used pretty well to find dead code that the compiler is
not able to detect because the functions get exporter from the
respective crates.

# Changes
just deletes dead code & removes some `drive` statements

## How to test
no logic change => compiler is enough
  • Loading branch information
MartinquaXD authored Dec 4, 2024
1 parent 1413398 commit 49871f2
Show file tree
Hide file tree
Showing 52 changed files with 18 additions and 964 deletions.
4 changes: 0 additions & 4 deletions crates/app-data/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ pub struct Hooks {
}

impl Hooks {
pub fn is_empty(&self) -> bool {
self.pre.is_empty() && self.post.is_empty()
}

pub fn gas_limit(&self) -> u64 {
std::iter::empty()
.chain(&self.pre)
Expand Down
85 changes: 0 additions & 85 deletions crates/autopilot/src/infra/blockchain/authenticator.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/autopilot/src/infra/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use {
url::Url,
};

pub mod authenticator;
pub mod contracts;

/// An Ethereum RPC connection.
Expand Down
21 changes: 1 addition & 20 deletions crates/autopilot/src/infra/solvers/dto/settle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
primitive_types::H256,
serde::{Deserialize, Serialize},
serde::Serialize,
serde_with::{serde_as, skip_serializing_none},
};

Expand All @@ -18,21 +17,3 @@ pub struct Request {
#[serde_as(as = "Option<serde_with::DisplayFromStr>")]
pub auction_id: Option<i64>,
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Response {
pub calldata: Calldata,
pub tx_hash: H256,
}

#[serde_as]
#[derive(Clone, Debug, Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Calldata {
#[serde(with = "bytes_hex")]
pub internalized: Vec<u8>,
#[serde(with = "bytes_hex")]
pub uninternalized: Vec<u8>,
}
12 changes: 0 additions & 12 deletions crates/autopilot/src/util/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,3 @@ impl<T> From<T> for Bytes<T> {
Self(value)
}
}

impl From<Bytes<Vec<u8>>> for Vec<u8> {
fn from(value: Bytes<Vec<u8>>) -> Self {
value.0
}
}

impl<const N: usize> From<Bytes<[u8; N]>> for [u8; N] {
fn from(value: Bytes<[u8; N]>) -> Self {
value.0
}
}
7 changes: 0 additions & 7 deletions crates/driver/src/domain/competition/order/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,6 @@ impl Jit {
}
}

/// Returns the signed fee of the order. You can't set this field in
/// the API so it's enforced to be 0. This function only exists to
/// not have magic values scattered everywhere.
pub fn fee(&self) -> SellAmount {
SellAmount(0.into())
}

/// Returns the signed partially fillable property of the order. You can't
/// set this field in the API so it's enforced to be fill-or-kill. This
/// function only exists to not have magic values scattered everywhere.
Expand Down
14 changes: 0 additions & 14 deletions crates/driver/src/domain/competition/order/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,3 @@ impl Scheme {
}
}
}

pub fn domain_separator(
chain_id: chain::Id,
verifying_contract: eth::ContractAddress,
) -> eth::DomainSeparator {
eth::DomainSeparator::new(&eth::DomainFields {
type_hash:
b"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)",
name: b"Gnosis Protocol",
version: b"v2",
chain_id,
verifying_contract,
})
}
9 changes: 0 additions & 9 deletions crates/driver/src/domain/competition/solution/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ impl Interaction {
}
}

/// The assets output by this interaction. These assets are sent into the
/// settlement contract when the interaction executes.
pub fn outputs(&self) -> Vec<eth::Asset> {
match self {
Interaction::Custom(custom) => custom.outputs.clone(),
Interaction::Liquidity(liquidity) => vec![liquidity.output],
}
}

/// Returns the ERC20 approvals required for executing this interaction
/// onchain.
pub fn allowances(&self) -> Vec<eth::allowance::Required> {
Expand Down
5 changes: 0 additions & 5 deletions crates/driver/src/domain/competition/solution/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ impl Settlement {
self.solution.id()
}

/// Address of the solver which generated this settlement.
pub fn solver(&self) -> eth::Address {
self.solution.solver().address()
}

/// The settled user orders with their in/out amounts.
pub fn orders(&self) -> HashMap<order::Uid, competition::Amounts> {
let log_err = |trade: &Trade, err: error::Math, kind: &str| -> eth::TokenAmount {
Expand Down
4 changes: 0 additions & 4 deletions crates/driver/src/domain/competition/solution/trade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ impl Fulfillment {
&self.order
}

pub fn side(&self) -> Side {
self.order.side
}

pub fn executed(&self) -> order::TargetAmount {
self.executed
}
Expand Down
34 changes: 0 additions & 34 deletions crates/driver/src/domain/eth/gas.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use {
super::{Ether, U256},
bigdecimal::Zero,
derive_more::{Display, From, Into},
std::{ops, ops::Add},
};
Expand All @@ -26,16 +25,6 @@ impl Add for Gas {
}
}

impl Zero for Gas {
fn zero() -> Self {
Self(U256::zero())
}

fn is_zero(&self) -> bool {
self.0.is_zero()
}
}

/// An EIP-1559 gas price estimate.
///
/// https://eips.ethereum.org/EIPS/eip-1559#specification
Expand Down Expand Up @@ -118,11 +107,6 @@ impl From<EffectiveGasPrice> for GasPrice {
pub struct FeePerGas(pub Ether);

impl FeePerGas {
/// Subtracts the given fee from this fee, saturating at zero.
pub fn saturating_sub(self, rhs: Self) -> Self {
self.0 .0.saturating_sub(rhs.0 .0).into()
}

/// Multiplies this fee by the given floating point number, rounding up.
fn mul_ceil(self, rhs: f64) -> Self {
U256::from_f64_lossy((self.0 .0.to_f64_lossy() * rhs).ceil()).into()
Expand Down Expand Up @@ -174,21 +158,3 @@ impl From<EffectiveGasPrice> for U256 {
value.0.into()
}
}

impl Add for EffectiveGasPrice {
type Output = Self;

fn add(self, rhs: Self) -> Self::Output {
Self(self.0 + rhs.0)
}
}

impl Zero for EffectiveGasPrice {
fn zero() -> Self {
Self(Ether::zero())
}

fn is_zero(&self) -> bool {
self.0.is_zero()
}
}
8 changes: 1 addition & 7 deletions crates/driver/src/infra/blockchain/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
self::contracts::ContractAt,
crate::{boundary, domain::eth},
ethcontract::dyns::DynWeb3,
ethcontract::{dyns::DynWeb3, errors::ExecutionError},
ethrpc::block_stream::CurrentBlockWatcher,
std::{fmt, sync::Arc},
thiserror::Error,
Expand All @@ -13,8 +13,6 @@ pub mod contracts;
pub mod gas;
pub mod token;

use {ethcontract::errors::ExecutionError, gas_estimation::GasPriceEstimating};

pub use self::{contracts::Contracts, gas::GasPriceEstimator};

/// An Ethereum RPC connection.
Expand Down Expand Up @@ -169,10 +167,6 @@ impl Ethereum {
Ok(access_list.into())
}

pub fn boundary_gas_estimator(&self) -> Arc<dyn GasPriceEstimating> {
self.inner.gas.gas.clone()
}

/// Estimate gas used by a transaction.
pub async fn estimate_gas(&self, tx: &eth::Tx) -> Result<eth::Gas, Error> {
self.web3
Expand Down
4 changes: 2 additions & 2 deletions crates/ethrpc/src/extensions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Module containing Ethereum RPC extension methods.
use {
serde::{Deserialize, Serialize},
serde::Serialize,
std::collections::HashMap,
web3::{
self,
Expand Down Expand Up @@ -50,7 +50,7 @@ where
pub type StateOverrides = HashMap<H160, StateOverride>;

/// State override object.
#[derive(Clone, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct StateOverride {
/// Fake balance to set for the account before executing the call.
Expand Down
1 change: 0 additions & 1 deletion crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub mod fee_policy;
pub mod interaction;
pub mod order;
pub mod quote;
pub mod ratio_as_decimal;
pub mod signature;
pub mod solver_competition;
pub mod time;
Expand Down
21 changes: 0 additions & 21 deletions crates/model/src/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ impl Order {
pub fn is_limit_order(&self) -> bool {
matches!(self.metadata.class, OrderClass::Limit)
}

/// For some orders the protocol doesn't precompute a fee. Instead solvers
/// are supposed to compute a reasonable fee themselves.
pub fn solver_determines_fee(&self) -> bool {
self.is_limit_order()
}
}

#[derive(Clone, Default, Debug)]
Expand Down Expand Up @@ -133,11 +127,6 @@ impl OrderBuilder {
self
}

pub fn with_full_fee_amount(mut self, full_fee_amount: U256) -> Self {
self.0.metadata.full_fee_amount = full_fee_amount;
self
}

pub fn with_kind(mut self, kind: OrderKind) -> Self {
self.0.data.kind = kind;
self
Expand Down Expand Up @@ -195,16 +184,6 @@ impl OrderBuilder {
self
}

pub fn with_solver_fee(mut self, fee: U256) -> Self {
self.0.metadata.solver_fee = fee;
self
}

pub fn with_full_app_data(mut self, full_app_data: String) -> Self {
self.0.metadata.full_app_data = Some(full_app_data);
self
}

pub fn build(self) -> Order {
self.0
}
Expand Down
Loading

0 comments on commit 49871f2

Please sign in to comment.