Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mouseless-eth committed Mar 19, 2023
1 parent e9c935f commit c794ed9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 98 deletions.
2 changes: 1 addition & 1 deletion bot/src/forked_db/fork_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use super::{

#[derive(Clone, Debug)]
pub struct ForkDB {
backend: Sender<BackendFetchRequest>,
// used to make calls for missing data
backend: Sender<BackendFetchRequest>,
db: CacheDB<EmptyDB>,
}

Expand Down
38 changes: 19 additions & 19 deletions bot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,22 @@ async fn main() -> Result<()> {
}
}

#[cfg(test)]
mod test {
use ethers::providers::Middleware;
use futures::StreamExt;
use rusty_sandwich::utils::testhelper;

#[tokio::test]
async fn sub_blocks() {
let client = testhelper::create_ws().await;
// let client = Provider::<Ws>::connect("ws://localhost:8545").await.unwrap();

let mut stream = client.subscribe_blocks().await.unwrap();
let mut prev = 0;
while let Some(block) = stream.next().await {
println!("{:#?}", block.timestamp.as_u32() - prev);
prev = block.timestamp.as_u32();
}
}
}
//#[cfg(test)]
//mod test {
// use ethers::providers::Middleware;
// use futures::StreamExt;
// use rusty_sandwich::utils::testhelper;
//
// #[tokio::test]
// async fn sub_blocks() {
// let client = testhelper::create_ws().await;
// // let client = Provider::<Ws>::connect("ws://localhost:8545").await.unwrap();
//
// let mut stream = client.subscribe_blocks().await.unwrap();
// let mut prev = 0;
// while let Some(block) = stream.next().await {
// println!("{:#?}", block.timestamp.as_u32() - prev);
// prev = block.timestamp.as_u32();
// }
// }
//}
75 changes: 0 additions & 75 deletions bot/src/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,78 +92,3 @@ pub async fn get_all_relay_endpoints() -> Vec<BundleRelay> {

relays
}

#[cfg(test)]
mod test {
use super::*;
use std::{str::FromStr, sync::Arc, time::Duration};

use ethers::prelude::rand::thread_rng;
use ethers_flashbots::FlashbotsMiddleware;
use reqwest::Url;

#[tokio::test]
async fn test_gas_sim() {
// Connect to the network
let provider = Provider::<Http>::try_from("https://relay.flashbots.net/").unwrap();

// This is your searcher identity
let bundle_signer = LocalWallet::new(&mut thread_rng());
// This signs transactions
let wallet = LocalWallet::new(&mut thread_rng());

// Add signer and Flashbots middleware
let fb_client = SignerMiddleware::new(
FlashbotsMiddleware::new(
provider,
Url::parse("https://relay.flashbots.net").unwrap(),
bundle_signer,
),
wallet,
);

let ws = Ws::connect("ws://localhost:8545").await.unwrap();
let ws_provider = Provider::new(ws).interval(Duration::from_millis(100));
let ws_provider = Arc::new(ws_provider);

let frontrun_hash =
TxHash::from_str("0x5c6c3212295421b026c437687ee482ed589ade60567b2dffb29c451d30aa3942")
.unwrap();
let frontrun_tx = ws_provider
.get_transaction(frontrun_hash)
.await
.unwrap()
.unwrap();

let victim_hash =
TxHash::from_str("0x8e46e9ec1b826252e85560f20e3bff1ceba9fda1c07766821d2ac32cc01c1c73")
.unwrap();
let victim_tx = ws_provider
.get_transaction(victim_hash)
.await
.unwrap()
.unwrap();

let backrun_hash =
TxHash::from_str("0x5df507650549411d6a6741d38b3f0248f17bd4835562e4a5a4d620d2192b2e9f")
.unwrap();
let backrun_tx = ws_provider
.get_transaction(backrun_hash)
.await
.unwrap()
.unwrap();

let target_block = ws_provider.get_block(16833583).await.unwrap().unwrap();
let sim_block = ws_provider.get_block(16833582).await.unwrap().unwrap();

let bundle = super::construct_bundle(
vec![frontrun_tx.rlp(), victim_tx.rlp(), backrun_tx.rlp()],
target_block.number.unwrap(),
sim_block.timestamp.as_u64(),
);

let simulation_result = fb_client.inner().simulate_bundle(&bundle).await;

println!("simulation_result: {:#?}", simulation_result);
}
}
2 changes: 1 addition & 1 deletion bot/src/simulate/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn get_balance_of_evm(
);

evm.env.tx.transact_to = TransactTo::Call(token.0.into());
evm.env.tx.data = erc20.encode("balanceOf", owner).unwrap().0; // getReserves()
evm.env.tx.data = erc20.encode("balanceOf", owner).unwrap().0;
evm.env.tx.caller = utils::constants::get_eth_dev().0.into();
evm.env.tx.gas_price = next_block.base_fee.into();
evm.env.tx.gas_limit = 700000;
Expand Down
1 change: 0 additions & 1 deletion bot/src/simulate/make_sandwich.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ async fn juiced_quadratic_search(
#[cfg(test)]
{
// if running test, setup contract sandwich to allow for backtest
// doing this incase backtesting before contract was deployed
// can also inject new sandwich code for testing
crate::prelude::inject_sando(&mut fork_factory, upper_bound);
}
Expand Down
2 changes: 1 addition & 1 deletion bot/src/utils/encode_packed.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Code yoinked from https://github.com/roberts-ivanovs/eth-encode-packed-rs
// credit to: https://github.com/roberts-ivanovs/eth-encode-packed-rs
pub use hex; // Re-export

use ethers::prelude::*;
Expand Down

0 comments on commit c794ed9

Please sign in to comment.