Skip to content

Commit

Permalink
fix: eip1559 estimator (#509)
Browse files Browse the repository at this point in the history
* fix: default estimator

* Add zero base fee test case
  • Loading branch information
klkvr authored Apr 11, 2024
1 parent 496d0e7 commit 9e6e34f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions crates/provider/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ pub fn eip1559_default_estimator(
let max_priority_fee_per_gas = estimate_priority_fee(rewards);
let potential_max_fee = base_fee_per_gas * EIP1559_BASE_FEE_MULTIPLIER;

Eip1559Estimation { max_fee_per_gas: potential_max_fee, max_priority_fee_per_gas }
Eip1559Estimation {
max_fee_per_gas: potential_max_fee + max_priority_fee_per_gas,
max_priority_fee_per_gas,
}
}

#[cfg(test)]
Expand Down Expand Up @@ -88,7 +91,22 @@ mod tests {
assert_eq!(
super::eip1559_default_estimator(base_fee_per_gas, &rewards),
Eip1559Estimation {
max_fee_per_gas: 2_000_000_000_u128,
max_fee_per_gas: 202_000_000_000_u128,
max_priority_fee_per_gas: 200_000_000_000_u128
}
);

let base_fee_per_gas = 0u128;
let rewards = vec![
vec![200_000_000_000_u128],
vec![200_000_000_000_u128],
vec![300_000_000_000_u128],
];

assert_eq!(
super::eip1559_default_estimator(base_fee_per_gas, &rewards),
Eip1559Estimation {
max_fee_per_gas: 200_000_000_000_u128,
max_priority_fee_per_gas: 200_000_000_000_u128
}
);
Expand Down

0 comments on commit 9e6e34f

Please sign in to comment.