Skip to content

Commit

Permalink
Replace Gas1559 with f64
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinquaXD committed Dec 8, 2023
1 parent 4e79635 commit a2cd56f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions crates/shared/src/price_estimation/competition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use {
FutureExt as _,
TryFutureExt,
},
gas_estimation::{GasPrice1559, GasPriceEstimating},
gas_estimation::GasPriceEstimating,
model::order::OrderKind,
primitive_types::{H160, U256},
std::{cmp::Ordering, fmt::Debug, num::NonZeroUsize, sync::Arc, time::Instant},
Expand Down Expand Up @@ -371,11 +371,7 @@ impl PriceRanking {
PriceRanking::MaxOutAmount => async {
Ok(RankingContext {
native_price: 1.0,
gas_price: GasPrice1559 {
base_fee_per_gas: 0.,
max_fee_per_gas: 0.,
max_priority_fee_per_gas: 0.,
},
gas_price: 0.,
})
}
.boxed(),
Expand All @@ -385,6 +381,7 @@ impl PriceRanking {
async move {
let gas = gas
.estimate()
.map_ok(|gas| gas.effective_gas_price())
.map_err(PriceEstimationError::ProtocolInternal);
let (native_price, gas_price) =
futures::try_join!(native.estimate_native_price(token), gas)?;
Expand All @@ -403,7 +400,7 @@ impl PriceRanking {

struct RankingContext {
native_price: f64,
gas_price: GasPrice1559,
gas_price: f64,
}

impl RankingContext {
Expand All @@ -414,7 +411,7 @@ impl RankingContext {
/// referred to as "bang-for-buck" and what matters most to traders.
fn effective_eth_out(&self, estimate: &Estimate) -> U256 {
let eth_out = estimate.out_amount.to_f64_lossy() * self.native_price;
let fees = estimate.gas as f64 * self.gas_price.effective_gas_price();
let fees = estimate.gas as f64 * self.gas_price;
let effective_eth_out = eth_out - fees;
// converts `NaN` and `(-∞, 0]` to `0`
U256::from_f64_lossy(effective_eth_out)
Expand Down

0 comments on commit a2cd56f

Please sign in to comment.