Skip to content

Commit

Permalink
Fix escalation fee logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 11, 2023
1 parent dad7ff5 commit 956ea8d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/tasks/escalate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,19 @@ pub async fn escalate_txs(app: Arc<App>) -> eyre::Result<()> {
.context("Missing block")?;

// Min increase of 20% on the priority fee required for a replacement tx
let factor = U256::from(100);
let increased_gas_price_percentage =
U256::from(100 + (10 * (1 + escalation)));
factor + U256::from(10 * (1 + escalation));

let factor = U256::from(100);
let max_fee_per_gas_increase = tx.initial_max_fee_per_gas.0
* increased_gas_price_percentage
/ factor;

let max_priority_fee_per_gas_increase =
tx.initial_max_priority_fee_per_gas.0
* increased_gas_price_percentage
/ factor;
let max_fee_per_gas =
tx.initial_max_fee_per_gas.0 + max_fee_per_gas_increase;

let max_priority_fee_per_gas =
tx.initial_max_priority_fee_per_gas.0
+ max_priority_fee_per_gas_increase;

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

let eip1559_tx = Eip1559TransactionRequest {
from: None,
Expand Down Expand Up @@ -84,8 +81,6 @@ pub async fn escalate_txs(app: Arc<App>) -> eyre::Result<()> {

let tx_hash = pending_tx.tx_hash();

tracing::info!(?tx.id, ?tx_hash, "Tx escalated");

app.db
.escalate_tx(
&tx.id,
Expand All @@ -94,6 +89,8 @@ pub async fn escalate_txs(app: Arc<App>) -> eyre::Result<()> {
max_priority_fee_per_gas,
)
.await?;

tracing::info!(?tx.id, ?tx_hash, "Tx escalated");
}

tokio::time::sleep(app.config.service.escalation_interval).await;
Expand Down

0 comments on commit 956ea8d

Please sign in to comment.