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

fix(sim): add fallback for polygon gasstaion failures #386

Merged
merged 1 commit into from
Sep 18, 2023
Merged
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
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
Loading