Skip to content

Commit

Permalink
Fix escalation fees calculation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Feb 15, 2024
1 parent 1de9292 commit 9be5bfb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/tasks/escalate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ async fn escalate_relayer_tx(
let increased_gas_price_percentage =
factor + U256::from(20 * (1 + escalation));

let initial_max_fee_per_gas = tx.initial_max_fee_per_gas.0;
let initial_max_priority_fee_per_gas =
tx.initial_max_priority_fee_per_gas.0;

let max_fee_per_gas_increase =
initial_max_fee_per_gas * increased_gas_price_percentage / factor;
let initial_max_fee_per_gas = tx.initial_max_fee_per_gas.0;

let max_fee_per_gas = initial_max_fee_per_gas + max_fee_per_gas_increase;
let max_priority_fee_per_gas = initial_max_priority_fee_per_gas
* increased_gas_price_percentage
/ factor;

let max_priority_fee_per_gas =
max_fee_per_gas - fees.fee_estimates.base_fee_per_gas;
let max_fee_per_gas =
max_priority_fee_per_gas + fees.fee_estimates.base_fee_per_gas;

let eip1559_tx = Eip1559TransactionRequest {
from: None,
Expand Down Expand Up @@ -154,16 +156,16 @@ async fn escalate_relayer_tx(
tracing::info!(
tx_id = tx.id,
?tx_hash,
?initial_max_priority_fee_per_gas,
?initial_max_fee_per_gas,
?max_fee_per_gas_increase,
?max_fee_per_gas,
?max_priority_fee_per_gas,
?max_fee_per_gas,
?pending_tx,
"Escalated transaction"
);

app.db
.escalate_tx(&tx.id, tx_hash, max_fee_per_gas, max_priority_fee_per_gas)
.escalate_tx(&tx.id, tx_hash, max_fee_per_gas, max_fee_per_gas)
.await?;

tracing::info!(tx_id = tx.id, "Escalated transaction saved");
Expand Down

0 comments on commit 9be5bfb

Please sign in to comment.