Skip to content

Commit

Permalink
fix(sim): add fallback for polygon gasstaion failures
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Sep 18, 2023
1 parent 6a83afa commit 69b6b0d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions crates/sim/src/gas/gas.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::Arc;

use anyhow::Context;
use ethers::{
prelude::gas_oracle::{GasCategory, GasOracle},
types::{Address, Chain, U256},
Expand Down Expand Up @@ -274,11 +273,17 @@ impl<P: Provider> FeeEstimator<P> {
if POLYGON_CHAIN_IDS.contains(&self.chain_id) {
let gas_oracle =
Polygon::new(Chain::try_from(self.chain_id)?)?.category(GasCategory::Fast);
let fees = gas_oracle
.estimate_eip1559_fees()
.await
.context("failed to query polygon gasstation")?;
Ok(fees.1)
match gas_oracle.estimate_eip1559_fees().await {
Ok(fees) => Ok(fees.1),
// Polygon gas station is very unreliable, fallback to max priority fee if it fails
// Fast can be 10% faster than what is returned by `eth_maxPriorityFeePerGas`
// so we increase the max priority fee by 10% to ensure that multiple
// calls to this endpoint give reasonably similar results.
Err(_) => Ok(math::increase_by_percent(
self.provider.get_max_priority_fee().await?,
10,
)),
}
} else if self.use_bundle_priority_fee {
self.provider.get_max_priority_fee().await
} else {
Expand Down

0 comments on commit 69b6b0d

Please sign in to comment.