Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor arguments display #491

Merged
merged 2 commits into from
Sep 1, 2022
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
28 changes: 15 additions & 13 deletions crates/autopilot/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct Arguments {
#[clap(long, env, use_value_delimiter = true)]
pub unsupported_tokens: Vec<H160>,

/// The fee value strategy to use for locating Uniswap V3 pools as token holders for bad token
/// detection.
#[clap(long, env, default_value = "static", arg_enum)]
pub token_detector_fee_values: FeeValues,

Expand Down Expand Up @@ -139,19 +141,19 @@ impl std::fmt::Display for Arguments {
)?;
writeln!(f, "skip_trace_api: {}", self.skip_trace_api)?;
writeln!(f, "pool_cache_lru_size: {}", self.pool_cache_lru_size)?;
write!(f, "balancer_sor_url: ")?;
write!(f, "price_estimation_rate_limiter: ")?;
display_option(&self.price_estimation_rate_limiter, f)?;
writeln!(f)?;
write!(f, "amount_to_estimate_prices_with: ")?;
display_option(&self.amount_to_estimate_prices_with, f)?;
writeln!(f)?;
write!(f, "quasimodo_solver_url: ")?;
display_option(&self.quasimodo_solver_url, f)?;
writeln!(f)?;
write!(f, "yearn_solver_url: ")?;
display_option(&self.yearn_solver_url, f)?;
writeln!(f)?;
display_option(f, "balancer_sor_url", &self.balancer_sor_url)?;
display_option(
f,
"price_estimation_rate_limiter",
&self.price_estimation_rate_limiter,
)?;
display_option(
f,
"amount_to_estimate_prices_with",
&self.amount_to_estimate_prices_with,
)?;
display_option(f, "quasimodo_solver_url", &self.quasimodo_solver_url)?;
display_option(f, "yearn_solver_url", &self.yearn_solver_url)?;
writeln!(
f,
"native_price_estimators: {:?}",
Expand Down
51 changes: 12 additions & 39 deletions crates/driver/src/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use primitive_types::{H160, H256};
use reqwest::Url;
use shared::{
arguments::{display_list, display_option, duration_from_seconds},
arguments::{display_list, display_option, display_secret_option, duration_from_seconds},
gas_price_estimation::GasEstimatorType,
sources::{balancer_v2::BalancerFactoryKind, BaselineSource},
};
Expand Down Expand Up @@ -267,9 +267,11 @@ impl std::fmt::Display for Arguments {
writeln!(f, "node_url: {}", self.node_url)?;
writeln!(f, "http_timeout: {:?}", self.http_timeout)?;
writeln!(f, "use_internal_buffers: {}", self.use_internal_buffers)?;
write!(f, "transaction_submission_nodes: ")?;
display_list(self.transaction_submission_nodes.iter(), f)?;
writeln!(f)?;
display_list(
f,
"transaction_submission_nodes",
&self.transaction_submission_nodes,
)?;
writeln!(
f,
"disable_high_risk_public_mempool_transactions: {}",
Expand All @@ -292,9 +294,7 @@ impl std::fmt::Display for Arguments {
"additional_tip_percentage: {}",
self.additional_tip_percentage
)?;
write!(f, "flashbots_api_url: ")?;
display_list(self.flashbots_api_url.iter(), f)?;
writeln!(f)?;
display_list(f, "flashbots_api_url", &self.flashbots_api_url)?;
writeln!(
f,
"max_additional_flashbots_tip: {}",
Expand All @@ -305,17 +305,8 @@ impl std::fmt::Display for Arguments {
"access_list_estimators: {:?}",
self.access_list_estimators
)?;
write!(f, "tenderly_url: ")?;
display_option(&self.tenderly_url, f)?;
writeln!(f)?;
writeln!(
f,
"tenderly_api_key: {}",
self.tenderly_api_key
.as_deref()
.map(|_| "SECRET")
.unwrap_or("None")
)?;
display_option(f, "tenderly_url", &self.tenderly_url)?;
display_secret_option(f, "tenderly_api_key", &self.tenderly_api_key)?;
writeln!(f, "simulation_gas_limit: {}", self.simulation_gas_limit)?;
writeln!(f, "target_confirm_time: {:?}", self.target_confirm_time)?;
writeln!(
Expand All @@ -330,14 +321,7 @@ impl std::fmt::Display for Arguments {
)?;
writeln!(f, "gas_price_cap: {}", self.gas_price_cap)?;
writeln!(f, "gas_estimators: {:?}", self.gas_estimators)?;
writeln!(
f,
"blocknative_api_key: {}",
self.blocknative_api_key
.as_ref()
.map(|_| "SECRET")
.unwrap_or("None")
)?;
display_secret_option(f, "blocknative_api_key", &self.blocknative_api_key)?;
writeln!(f, "base_tokens: {:?}", self.base_tokens)?;
writeln!(f, "baseline_sources: {:?}", self.baseline_sources)?;
writeln!(f, "pool_cache_blocks: {}", self.pool_cache_blocks)?;
Expand Down Expand Up @@ -372,19 +356,8 @@ impl std::fmt::Display for Arguments {
"liquidity_fetcher_max_age_update: {:?}",
self.liquidity_fetcher_max_age_update
)?;
writeln!(
f,
"zeroex_url: {}",
self.zeroex_url.as_deref().unwrap_or("None")
)?;
writeln!(
f,
"zeroex_api_key: {}",
self.zeroex_api_key
.as_ref()
.map(|_| "SECRET")
.unwrap_or("None")
)?;
display_option(f, "zeroex_url", &self.zeroex_url)?;
display_secret_option(f, "zeroex_api_key", &self.zeroex_api_key)?;
Ok(())
}
}
30 changes: 14 additions & 16 deletions crates/orderbook/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ impl std::fmt::Display for Arguments {
writeln!(f, "enable_presign_orders: {}", self.enable_presign_orders)?;
writeln!(
f,
"solvable_orders_max_update_age_blocks: {:?}",
"solvable_orders_max_update_age_blocks: {}",
self.solvable_orders_max_update_age_blocks,
)?;
writeln!(f, "fee_discount: {}", self.fee_discount)?;
Expand All @@ -291,12 +291,8 @@ impl std::fmt::Display for Arguments {
self.partner_additional_fee_factors
)?;
writeln!(f, "cow_fee_factors: {:?}", self.cow_fee_factors)?;
write!(f, "quasimodo_solver_url: ")?;
display_option(&self.quasimodo_solver_url, f)?;
writeln!(f)?;
write!(f, "yearn_solver_url: ")?;
display_option(&self.yearn_solver_url, f)?;
writeln!(f)?;
display_option(f, "quasimodo_solver_url", &self.quasimodo_solver_url)?;
display_option(f, "yearn_solver_url", &self.yearn_solver_url)?;
writeln!(
f,
"native_price_cache_max_age_secs: {:?}",
Expand All @@ -312,18 +308,22 @@ impl std::fmt::Display for Arguments {
"native_price_estimators: {:?}",
self.native_price_estimators
)?;
write!(f, "amount_to_estimate_prices_with: ")?;
display_option(&self.amount_to_estimate_prices_with, f)?;
writeln!(f)?;
display_option(
f,
"amount_to_estimate_prices_with",
&self.amount_to_estimate_prices_with,
)?;
writeln!(f, "price_estimators: {:?}", self.price_estimators)?;
writeln!(
f,
"fast_price_estimation_results_required: {}",
self.fast_price_estimation_results_required
)?;
write!(f, "price_estimation_rate_limiter: ")?;
display_option(&self.price_estimation_rate_limiter, f)?;
writeln!(f)?;
display_option(
f,
"price_estimation_rate_limites",
&self.price_estimation_rate_limiter,
)?;
writeln!(
f,
"token_detector_fee_values: {:?}",
Expand All @@ -335,9 +335,7 @@ impl std::fmt::Display for Arguments {
self.liquidity_order_owners
)?;
writeln!(f, "enable_blockscout: {}", self.enable_blockscout)?;
write!(f, "balancer_sor_url: ")?;
display_option(&self.balancer_sor_url, f)?;
writeln!(f)?;
display_option(f, "balancer_sor_url", &self.balancer_sor_url)?;
Ok(())
}
}
Expand Down
106 changes: 43 additions & 63 deletions crates/shared/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,42 @@ pub struct Arguments {
pub liquidity_fetcher_max_age_update: Duration,
}

pub fn display_option(option: &Option<impl Display>, f: &mut Formatter<'_>) -> std::fmt::Result {
pub fn display_secret_option<T>(
f: &mut Formatter<'_>,
name: &str,
option: &Option<T>,
) -> std::fmt::Result {
display_option(f, name, &option.as_ref().map(|_| "SECRET"))
}

pub fn display_option(
f: &mut Formatter<'_>,
name: &str,
option: &Option<impl Display>,
) -> std::fmt::Result {
write!(f, "{name}: ")?;
match option {
Some(display) => write!(f, "{}", display),
None => write!(f, "None"),
Some(display) => writeln!(f, "{}", display),
None => writeln!(f, "None"),
}
}

pub fn display_list<T>(iter: impl Iterator<Item = T>, f: &mut Formatter<'_>) -> std::fmt::Result
pub fn display_list<T>(
f: &mut Formatter<'_>,
name: &str,
iter: impl IntoIterator<Item = T>,
) -> std::fmt::Result
where
T: Display,
{
write!(f, "[")?;
for t in iter {
write!(f, "{}, ", t)?;
write!(f, "{name}: [")?;
for (i, t) in iter.into_iter().enumerate() {
if i != 0 {
f.write_str(", ")?;
}
write!(f, "{t}")?;
}
write!(f, "]")?;
writeln!(f, "]")?;
Ok(())
}

Expand All @@ -197,14 +217,7 @@ impl Display for Arguments {
writeln!(f, "node_url: {}", self.node_url)?;
writeln!(f, "http_timeout: {:?}", self.http_timeout)?;
writeln!(f, "gas_estimators: {:?}", self.gas_estimators)?;
writeln!(
f,
"blocknative_api_key: {}",
self.blocknative_api_key
.as_ref()
.map(|_| "SECRET")
.unwrap_or("None")
)?;
display_secret_option(f, "blocknative_api_key", &self.blocknative_api_key)?;
writeln!(f, "base_tokens: {:?}", self.base_tokens)?;
writeln!(f, "baseline_sources: {:?}", self.baseline_sources)?;
writeln!(f, "pool_cache_blocks: {}", self.pool_cache_blocks)?;
Expand All @@ -226,37 +239,13 @@ impl Display for Arguments {
writeln!(
f,
"block_stream_poll_interval_seconds: {:?}",
self.block_stream_poll_interval_seconds
)?;
writeln!(
f,
"paraswap_partner: {}",
self.paraswap_partner
.as_ref()
.map(|_| "SECRET")
.unwrap_or("None")
)?;
writeln!(
f,
"disabled_paraswap_dexs: {:?}",
self.disabled_paraswap_dexs
)?;
write!(f, "paraswap_rate_limiter: ")?;
display_option(&self.paraswap_rate_limiter, f)?;
writeln!(f)?;
writeln!(
f,
"zeroex_url: {}",
self.zeroex_url.as_deref().unwrap_or("None")
)?;
writeln!(
f,
"zeroex_api_key: {}",
self.zeroex_api_key
.as_ref()
.map(|_| "SECRET")
.unwrap_or("None")
self.block_stream_poll_interval_seconds,
)?;
display_secret_option(f, "paraswap_partner", &self.paraswap_partner)?;
display_list(f, "disabled_paraswap_dexs", &self.disabled_paraswap_dexs)?;
display_option(f, "paraswap_rate_limiter", &self.paraswap_rate_limiter)?;
display_option(f, "zeroex_url", &self.zeroex_url)?;
display_secret_option(f, "zeroex_api_key", &self.zeroex_api_key)?;
writeln!(
f,
"quasimodo_uses_internal_buffers: {}",
Expand All @@ -268,33 +257,24 @@ impl Display for Arguments {
self.mip_uses_internal_buffers
)?;
writeln!(f, "balancer_factories: {:?}", self.balancer_factories)?;
writeln!(
display_list(
f,
"disabled_one_inch_protocols: {:?}",
self.disabled_one_inch_protocols
"disabled_one_inch_protocols",
&self.disabled_one_inch_protocols,
)?;
writeln!(f, "one_inch_url: {}", self.one_inch_url)?;
write!(f, "one_inch_referrer_address: ")?;
display_option(&self.one_inch_referrer_address.map(|a| format!("{a:?}")), f)?;
writeln!(f)?;
writeln!(
display_option(
f,
"disabled_zeroex_sources: {:?}",
self.disabled_zeroex_sources
"one_inch_referrer_address",
&self.one_inch_referrer_address.map(|a| format!("{a:?}")),
)?;
display_list(f, "disabled_zeroex_sources", &self.disabled_zeroex_sources)?;
writeln!(
f,
"balancer_pool_deny_list: {:?}",
self.balancer_pool_deny_list
)?;
writeln!(
f,
"solver_competition_auth: {}",
self.solver_competition_auth
.as_ref()
.map(|_| "SECRET")
.unwrap_or("None")
)?;
display_secret_option(f, "solver_competition_auth", &self.solver_competition_auth)?;
Ok(())
}
}
Expand Down
Loading