Skip to content

Commit

Permalink
Add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
10xc0ffee committed Aug 10, 2023
1 parent 5853be6 commit 2b5b212
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bot/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
WSS_RPC=ws://localhost:8545
WSS_RPC=wss://capable-crimson-vineyard.discover.quiknode.pro/b0f808fe30ebe9dd7b2a7122c563e20f1e9966da/
SEARCHER_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000001
FLASHBOTS_AUTH_KEY=0000000000000000000000000000000000000000000000000000000000000002
SANDWICH_CONTRACT=0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa
Expand Down
3 changes: 2 additions & 1 deletion bot/crates/strategy/src/bot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub struct SandoBot<M> {
sando_state_manager: SandoStateManager,
}

impl<M: Middleware + 'static> SandoBot<M> {
impl<M> SandoBot<M> where M : Middleware + 'static
{
/// Create a new instance
pub fn new(client: Arc<M>, config: StratConfig) -> Self {
Self {
Expand Down
4 changes: 4 additions & 0 deletions bot/crates/strategy/src/managers/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ impl<M: Middleware + 'static> PoolManager<M> {
// right now bot can only sandwich `weth->token` trades
// enhancement: add support for `token->weth` trades (using longtail or flashswaps sandos)
if to > from {
// From and to are balances of the ERC20 Token in WETH's address. If t is increasing, that means the tx
// is trading WETH for the token.
// So a frontrun tx transfering weth->token, plus the victim tx, plus the backrun
// tx token->weth, forms the sandwich attack.
sandwichable_pools.push(pool);
}
}
Expand Down
8 changes: 8 additions & 0 deletions bot/crates/strategy/src/simulator/huff_sando.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub fn create_recipe(
#[allow(unused_mut)]
let mut fork_db = CacheDB::new(shared_backend);


// Where do we check the optimal_in is less thanthe weth_inventory in the
// searcher' address?

// why below
#[cfg(feature = "debug")]
{
inject_huff_sando(
Expand Down Expand Up @@ -153,7 +158,9 @@ pub fn create_recipe(
TransactTo::Call(rAddress::from_slice(&meat.to.unwrap_or_default().0));
evm.env.tx.data = meat.input.0.clone();
evm.env.tx.value = meat.value.into();
// Why we set the chain id here?
evm.env.tx.chain_id = meat.chain_id.map(|id| id.as_u64());
// Should we check nonce to prevent any fake tx?
//evm.env.tx.nonce = Some(meat.nonce.as_u64());
evm.env.tx.gas_limit = meat.gas.as_u64();
match meat.transaction_type {
Expand Down Expand Up @@ -239,6 +246,7 @@ pub fn create_recipe(
evm.env.tx = backrun_tx_env.clone();

// create access list
// Why we need to use access list here
let mut access_list_inspector = AccessListTracer::new(
Default::default(),
searcher,
Expand Down
1 change: 1 addition & 0 deletions bot/crates/strategy/src/simulator/lil_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ async fn evaluate_sandwich_revenue(
// evm.env.tx.nonce = Some(meat.nonce.as_u64()); /** ignore nonce check for now **/
evm.env.tx.gas_limit = meat.gas.as_u64();
match meat.transaction_type {
// 1. Why we use U64([0]) (an array) here; 2. why Some(0) is a legacy type
Some(ethers::types::U64([0])) => {
// legacy tx
evm.env.tx.gas_price = meat.gas_price.unwrap_or_default().into();
Expand Down
1 change: 1 addition & 0 deletions bot/crates/strategy/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ impl SandoRecipe {
value: Some(self.frontrun.value.into()),
data: Some(self.frontrun.data.into()),
nonce: Some(nonce),
// What is the transaction_type with this constructor?
access_list: access_list_to_ethers(self.frontrun.access_list),
max_fee_per_gas: Some(self.target_block.base_fee_per_gas.into()),
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions bot/sando-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async fn main() -> Result<()> {
engine.add_collector(Box::new(block_collector));

// Setup mempool collector
let mempool_collector = Box::new(MempoolCollector::new(provider.clone()));
let mempool_collector = CollectorMap::new(mempool_collector, Event::NewTransaction);
let mempool_collector: Box<MempoolCollector<Provider<Ws>>> = Box::new(MempoolCollector::new(provider.clone()));
let mempool_collector = CollectorMap::new(mempool_collector, Event::NewTransaction);
engine.add_collector(Box::new(mempool_collector));

// Setup strategy
Expand Down

0 comments on commit 2b5b212

Please sign in to comment.