Skip to content

Commit

Permalink
Remove fake-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzejkop committed Dec 21, 2023
1 parent b1751a0 commit 2f0b25d
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 373 deletions.
38 changes: 0 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ url = "2.4.1"
uuid = { version = "0.8", features = ["v4"] }

[dev-dependencies]
fake-rpc = { path = "crates/fake-rpc" }
indoc = "2.0.3"
test-case = "3.1.0"

Expand Down
52 changes: 0 additions & 52 deletions crates/fake-rpc/Cargo.toml

This file was deleted.

153 changes: 0 additions & 153 deletions crates/fake-rpc/src/lib.rs

This file was deleted.

30 changes: 0 additions & 30 deletions crates/fake-rpc/src/main.rs

This file was deleted.

40 changes: 10 additions & 30 deletions src/broadcast_utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ethers::types::{Eip1559TransactionRequest, U256};
use ethers::types::U256;
use eyre::ContextCompat;

use self::gas_estimation::FeesEstimate;
Expand All @@ -12,40 +12,20 @@ pub fn calculate_gas_fees_from_estimates(
tx_priority_index: usize,
max_base_fee_per_gas: U256,
) -> (U256, U256) {
println!("estimates = {estimates:#?}");

let max_priority_fee_per_gas = estimates.percentile_fees[tx_priority_index];

let max_fee_per_gas = max_base_fee_per_gas + max_priority_fee_per_gas;

(max_fee_per_gas, max_priority_fee_per_gas)
}

pub fn escalate_priority_fee(
max_base_fee_per_gas: U256,
max_network_fee_per_gas: U256,
current_max_priority_fee_per_gas: U256,
escalation_count: usize,
tx: &mut Eip1559TransactionRequest,
) {
// Min increase of 20% on the priority fee required for a replacement tx
let increased_gas_price_percentage =
U256::from(100 + (10 * (1 + escalation_count)));

let factor = U256::from(100);

let new_max_priority_fee_per_gas = current_max_priority_fee_per_gas
* increased_gas_price_percentage
/ factor;

let new_max_priority_fee_per_gas =
std::cmp::min(new_max_priority_fee_per_gas, max_network_fee_per_gas);
println!(
"max_base_fee_per_gas = {max_base_fee_per_gas}, max_priority_fee_per_gas = {max_priority_fee_per_gas}, max_fee_per_gas = {max_fee_per_gas}",
max_base_fee_per_gas = max_base_fee_per_gas,
max_priority_fee_per_gas = max_priority_fee_per_gas,
max_fee_per_gas = max_fee_per_gas,
);

let new_max_fee_per_gas =
max_base_fee_per_gas + new_max_priority_fee_per_gas;
let new_max_fee_per_gas =
std::cmp::min(new_max_fee_per_gas, max_network_fee_per_gas);

tx.max_fee_per_gas = Some(new_max_fee_per_gas);
tx.max_priority_fee_per_gas = Some(new_max_priority_fee_per_gas);
(max_fee_per_gas, max_priority_fee_per_gas)
}

pub async fn should_send_transaction(
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Duration;
use ethers::providers::Middleware;

Check warning on line 5 in src/tasks/broadcast.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/tx-sitter-monolith/tx-sitter-monolith/src/tasks/broadcast.rs

Check warning on line 5 in src/tasks/broadcast.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/tx-sitter-monolith/tx-sitter-monolith/src/tasks/broadcast.rs
use ethers::types::transaction::eip2718::TypedTransaction;
use ethers::types::transaction::eip2930::AccessList;
use ethers::types::{Address, Eip1559TransactionRequest, NameOrAddress, H256};
use ethers::types::{Address, Eip1559TransactionRequest, NameOrAddress, H256, U256};

Check failure on line 8 in src/tasks/broadcast.rs

View workflow job for this annotation

GitHub Actions / cargo test

unused import: `U256`

Check failure on line 8 in src/tasks/broadcast.rs

View workflow job for this annotation

GitHub Actions / cargo test

unused import: `U256`
use eyre::ContextCompat;
use futures::stream::FuturesUnordered;
use futures::StreamExt;
Expand Down
9 changes: 8 additions & 1 deletion src/tasks/escalate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn escalate_txs(app: Arc<App>) -> eyre::Result<()> {
// Min increase of 20% on the priority fee required for a replacement tx
let factor = U256::from(100);
let increased_gas_price_percentage =
factor + U256::from(10 * (1 + escalation));
factor + U256::from(20 * (1 + escalation));

let max_fee_per_gas_increase = tx.initial_max_fee_per_gas.0
* increased_gas_price_percentage
Expand All @@ -51,6 +51,13 @@ pub async fn escalate_txs(app: Arc<App>) -> eyre::Result<()> {
let max_priority_fee_per_gas =
max_fee_per_gas - fees.fee_estimates.base_fee_per_gas;

tracing::warn!(
"Initial tx fees are max = {}, priority = {}",
tx.initial_max_fee_per_gas.0,
tx.initial_max_priority_fee_per_gas.0
);
tracing::warn!("Escalating with max fee = {max_fee_per_gas} and max priority = {max_priority_fee_per_gas}");

let eip1559_tx = Eip1559TransactionRequest {
from: None,
to: Some(NameOrAddress::from(Address::from(tx.tx_to.0))),
Expand Down
Loading

0 comments on commit 2f0b25d

Please sign in to comment.