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

polygon gas price estimation fix #30

Merged
merged 2 commits into from
Jan 9, 2025
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
12 changes: 8 additions & 4 deletions ethers-middleware/src/gas_oracle/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use url::Url;
const MAINNET_URL: &str = "https://gasstation.polygon.technology/v2";
const MUMBAI_URL: &str = "https://gasstation-testnet.polygon.technology/v2";

const BASE_FEE_MULTIPLIER: f64 = 1.5;
const PRIO_FEE_MULTIPLIER: f64 = 1.1;

/// The [Polygon](https://docs.polygon.technology/docs/develop/tools/polygon-gas-station/) gas station API
/// Queries over HTTP and implements the `GasOracle` trait
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -71,17 +74,18 @@ impl Response {
impl GasOracle for Polygon {
async fn fetch(&self) -> Result<U256, GasOracleError> {
let response = self.query().await?;
let base = response.estimated_base_fee;
let prio = response.estimate_from_category(self.gas_category).max_priority_fee;
let base = response.estimated_base_fee * BASE_FEE_MULTIPLIER;
let prio = response.estimate_from_category(self.gas_category).max_priority_fee
* PRIO_FEE_MULTIPLIER;
let fee = base + prio;
Ok(from_gwei(fee))
}

async fn estimate_eip1559_fees(&self) -> Result<(U256, U256), GasOracleError> {
let response = self.query().await?;
let estimate = response.estimate_from_category(self.gas_category);
let max = from_gwei(estimate.max_fee);
let prio = from_gwei(estimate.max_priority_fee);
let max = from_gwei(estimate.max_fee * BASE_FEE_MULTIPLIER);
let prio = from_gwei(estimate.max_priority_fee * PRIO_FEE_MULTIPLIER);
Ok((max, prio))
}
}
Expand Down
Loading