Skip to content
Closed
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
1 change: 0 additions & 1 deletion crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ pub async fn run(args: Arguments, shutdown_controller: ShutdownController) {
.unwrap(),
},
balance_fetcher.clone(),
args.price_estimation.quote_verification,
args.price_estimation.quote_timeout,
));

Expand Down
1 change: 0 additions & 1 deletion crates/e2e/src/setup/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ impl<'a> Services<'a> {
let args: Vec<_> = [
"orderbook".to_string(),
"--quote-timeout=10s".to_string(),
"--quote-verification=enforce-when-possible".to_string(),
]
.into_iter()
.chain(self.api_autopilot_solver_arguments())
Expand Down
5 changes: 2 additions & 3 deletions crates/e2e/tests/e2e/replace_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,8 @@ async fn single_replace_order_test(web3: Web3) {
.start_protocol_with_args(
ExtraServiceArgs {
// To avoid race conditions we have to start the protocol
// with the solver being banned. To allow us to still create
// orders we override the quote verification to be disabled.
api: vec!["--quote-verification=prefer".into()],
// with the solver being banned.
api: vec![],
..Default::default()
},
solver.clone(),
Expand Down
30 changes: 24 additions & 6 deletions crates/orderbook/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ use {
order_validation::{OrderValidPeriodConfiguration, OrderValidator},
price_estimation::{
PriceEstimating,
QuoteVerificationMode,
factory::{self, PriceEstimatorFactory},
native::NativePriceEstimating,
},
Expand Down Expand Up @@ -365,8 +364,7 @@ pub async fn run(args: Arguments) {
max_limit: args.max_limit_order_validity_period,
};

let create_quoter = |price_estimator: Arc<dyn PriceEstimating>,
verification: QuoteVerificationMode| {
let create_quoter = |price_estimator: Arc<dyn PriceEstimating>| {
Arc::new(OrderQuoter::new(
price_estimator,
native_price_estimator.clone(),
Expand All @@ -387,16 +385,36 @@ pub async fn run(args: Arguments) {
.unwrap(),
},
balance_fetcher.clone(),
verification,
args.price_estimation.quote_timeout,
))
};
let optimal_quoter = create_quoter(price_estimator, args.price_estimation.quote_verification);
let optimal_quoter = create_quoter(price_estimator);
// Fast quoting is able to return early and if none of the produced quotes are
// verifiable we are left with no quote at all. Since fast estimates don't
// make any promises on correctness we can just skip quote verification for
// them.
let fast_quoter = create_quoter(fast_price_estimator, QuoteVerificationMode::Unverified);
let fast_quoter = Arc::new(OrderQuoter::new(
fast_price_estimator,
native_price_estimator.clone(),
gas_price_estimator.clone(),
Arc::new(postgres_write.clone()),
order_quoting::Validity {
eip1271_onchain_quote: chrono::Duration::from_std(
args.order_quoting.eip1271_onchain_quote_validity,
)
.unwrap(),
presign_onchain_quote: chrono::Duration::from_std(
args.order_quoting.presign_onchain_quote_validity,
)
.unwrap(),
standard_quote: chrono::Duration::from_std(
args.order_quoting.standard_offchain_quote_validity,
)
.unwrap(),
},
balance_fetcher.clone(),
args.price_estimation.quote_timeout,
));

let app_data_validator = Validator::new(args.app_data_size_limit);
let chainalysis_oracle = ChainalysisOracle::Instance::deployed(&web3.alloy)
Expand Down
24 changes: 3 additions & 21 deletions crates/shared/src/order_quoting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use {
db_order_conversions::order_kind_from,
fee::FeeParameters,
order_validation::PreOrderData,
price_estimation::{Estimate, QuoteVerificationMode, Verification},
price_estimation::{Estimate, Verification},
trade_finding::external::dto,
},
anyhow::{Context, Result},
Expand Down Expand Up @@ -412,7 +412,6 @@ pub struct OrderQuoter {
now: Arc<dyn Now>,
validity: Validity,
balance_fetcher: Arc<dyn BalanceFetching>,
quote_verification: QuoteVerificationMode,
default_quote_timeout: std::time::Duration,
}

Expand All @@ -425,7 +424,6 @@ impl OrderQuoter {
storage: Arc<dyn QuoteStoring>,
validity: Validity,
balance_fetcher: Arc<dyn BalanceFetching>,
quote_verification: QuoteVerificationMode,
default_quote_timeout: std::time::Duration,
) -> Self {
Self {
Expand All @@ -436,7 +434,6 @@ impl OrderQuoter {
now: Arc::new(Utc::now),
validity,
balance_fetcher,
quote_verification,
default_quote_timeout,
}
}
Expand Down Expand Up @@ -528,13 +525,8 @@ impl OrderQuoter {
parameters: &QuoteParameters,
sell_amount: U256,
) -> Result<(), CalculateQuoteError> {
if estimate.verified
|| !matches!(
self.quote_verification,
QuoteVerificationMode::EnforceWhenPossible
)
{
// verification was successful or not strictly required
// Always prefer verified quotes - accept both verified and unverified
if estimate.verified {
return Ok(());
}

Expand Down Expand Up @@ -926,7 +918,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: super::Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1067,7 +1058,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1203,7 +1193,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1302,7 +1291,6 @@ mod tests {
storage: Arc::new(MockQuoteStoring::new()),
now: Arc::new(Utc::now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1376,7 +1364,6 @@ mod tests {
storage: Arc::new(MockQuoteStoring::new()),
now: Arc::new(Utc::now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1437,7 +1424,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1520,7 +1506,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1605,7 +1590,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1678,7 +1662,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down Expand Up @@ -1709,7 +1692,6 @@ mod tests {
storage: Arc::new(storage),
now: Arc::new(Utc::now),
validity: Validity::default(),
quote_verification: QuoteVerificationMode::Unverified,
balance_fetcher: mock_balance_fetcher(),
default_quote_timeout: HEALTHY_PRICE_ESTIMATION_TIME,
};
Expand Down
14 changes: 2 additions & 12 deletions crates/shared/src/price_estimation/competition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,7 @@ impl<T: Send + Sync + 'static> CompetitionEstimator<T> {
stages,
usable_results_for_early_return: NonZeroUsize::MAX,
ranking,
verification_mode: QuoteVerificationMode::Unverified,
}
}

/// Configures if verified price estimates should be ranked higher than
/// unverified ones even if the price is worse.
/// Per default verified quotes do not get preferred.
pub fn with_verification(self, mode: QuoteVerificationMode) -> Self {
Self {
verification_mode: mode,
..self
verification_mode: QuoteVerificationMode::Prefer,
}
}

Expand Down Expand Up @@ -585,7 +575,7 @@ mod tests {
],
usable_results_for_early_return: NonZeroUsize::new(2).unwrap(),
ranking: PriceRanking::MaxOutAmount,
verification_mode: QuoteVerificationMode::Unverified,
verification_mode: QuoteVerificationMode::Prefer,
};

racing.estimate(query).await.unwrap();
Expand Down
14 changes: 1 addition & 13 deletions crates/shared/src/price_estimation/competition/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ mod tests {
gas_price_estimation::FakeGasPriceEstimator,
price_estimation::{
MockPriceEstimating,
QuoteVerificationMode,
native::MockNativePriceEstimating,
},
},
Expand Down Expand Up @@ -202,7 +201,6 @@ mod tests {
ranking: PriceRanking,
kind: OrderKind,
estimates: Vec<PriceEstimateResult>,
verification: QuoteVerificationMode,
) -> PriceEstimateResult {
fn estimator(estimate: PriceEstimateResult) -> Arc<dyn PriceEstimating> {
let mut estimator = MockPriceEstimating::new();
Expand All @@ -222,8 +220,7 @@ mod tests {
.collect(),
],
ranking.clone(),
)
.with_verification(verification);
);

priority
.estimate(Arc::new(Query {
Expand All @@ -249,7 +246,6 @@ mod tests {
// User effectively receives `99_999` `buy_token`.
price(107_999, 2_000),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, price(104_000, 1_000));
Expand All @@ -263,7 +259,6 @@ mod tests {
// User effectively pays `100_002` `sell_token`.
price(92_002, 2_000),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, price(96_000, 1_000));
Expand All @@ -287,7 +282,6 @@ mod tests {
// gets discarded because it quotes 0 gas.
price(104_000, 0),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, price(104_000, 1_000));
Expand All @@ -304,7 +298,6 @@ mod tests {
// gets discarded because it quotes 0 gas.
price(99_000, 0),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, price(96_000, 1_000));
Expand All @@ -322,7 +315,6 @@ mod tests {
error(PriceEstimationError::RateLimited),
error(PriceEstimationError::ProtocolInternal(anyhow::anyhow!("!"))),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, error(PriceEstimationError::RateLimited));
Expand All @@ -338,7 +330,6 @@ mod tests {
price(1, 1_000_000),
error(PriceEstimationError::RateLimited),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, price(1, 1_000_000));
Expand Down Expand Up @@ -366,7 +357,6 @@ mod tests {
better_unverified_quote.clone(),
worse_verified_quote.clone(),
],
QuoteVerificationMode::Prefer,
)
.await;
assert_eq!(best, worse_verified_quote.clone());
Expand All @@ -378,7 +368,6 @@ mod tests {
better_unverified_quote.clone(),
worse_verified_quote.clone(),
],
QuoteVerificationMode::EnforceWhenPossible,
)
.await;
assert_eq!(best, worse_verified_quote.clone());
Expand All @@ -390,7 +379,6 @@ mod tests {
better_unverified_quote.clone(),
worse_verified_quote.clone(),
],
QuoteVerificationMode::Unverified,
)
.await;
assert_eq!(best, better_unverified_quote);
Expand Down
4 changes: 1 addition & 3 deletions crates/shared/src/price_estimation/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ impl<'a> PriceEstimatorFactory<'a> {
let competition_estimator = CompetitionEstimator::new(
vec![estimators],
PriceRanking::BestBangForBuck { native, gas },
)
.with_verification(self.args.quote_verification);
);
Ok(Arc::new(self.sanitized(Arc::new(competition_estimator))))
}

Expand Down Expand Up @@ -358,7 +357,6 @@ impl<'a> PriceEstimatorFactory<'a> {

let competition_estimator =
CompetitionEstimator::new(estimators, PriceRanking::MaxOutAmount)
.with_verification(self.args.quote_verification)
.with_early_return(results_required);
let native_estimator = Arc::new(CachingNativePriceEstimator::new(
Box::new(competition_estimator),
Expand Down
12 changes: 0 additions & 12 deletions crates/shared/src/price_estimation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,6 @@ pub struct Arguments {
#[clap(long, env, default_value = "1.")]
pub quote_inaccuracy_limit: BigDecimal,

/// How strict quote verification should be.
#[clap(
long,
env,
default_value = "unverified",
value_enum,
verbatim_doc_comment
)]
pub quote_verification: QuoteVerificationMode,

/// Default timeout for quote requests.
#[clap(
long,
Expand Down Expand Up @@ -357,7 +347,6 @@ impl Display for Arguments {
one_inch_url,
coin_gecko,
quote_inaccuracy_limit,
quote_verification,
quote_timeout,
balance_overrides,
native_price_approximation_tokens,
Expand Down Expand Up @@ -424,7 +413,6 @@ impl Display for Arguments {
),
)?;
writeln!(f, "quote_inaccuracy_limit: {quote_inaccuracy_limit}")?;
writeln!(f, "quote_verification: {quote_verification:?}")?;
writeln!(f, "quote_timeout: {quote_timeout:?}")?;
write!(f, "{balance_overrides}")?;
writeln!(
Expand Down