mouseless0x / rusty-sando

Implementation of a competitive v2/v3 multi-meat MEV sandwich bot written using Rust and Huff.
MIT License
782 stars 256 forks source link

Tests Failure #4

Closed e7172 closed 1 year ago

e7172 commented 1 year ago

Hi,

We are having this error in all tests:

---- simulate::make_sandwich::test::sandv2_multi_with_three_expect_one_reverts stdout ---- thread 'simulate::make_sandwich::test::sandv2_multi_with_three_expect_one_reverts' panicked at 'calledOption::unwrap()on aNonevalue', src/simulate/make_sandwich.rs:696:10

We think is because this:

From: bot/src/utils/state_diff.rs

pub async fn get_from_txs(
    client: &Arc<Provider<Ws>>,
    meats: &Vec<Transaction>,
    block_num: BlockNumber,
) -> Option<BTreeMap<Address, AccountDiff>> {
    // add statediff trace to each transaction
    let req = meats
        .iter()
        .map(|tx| (tx, vec![TraceType::StateDiff]))
        .collect();

    let block_traces = match client.trace_call_many(req, Some(block_num)).await {
        Ok(x) => x,
        Err(_) => {
            // should throw error here but guess None also works :<
            return None;
        }
    };

    let mut merged_state_diffs = BTreeMap::new();

    block_traces
        .into_iter()
        .flat_map(|bt| bt.state_diff.map(|sd| sd.0.into_iter()))
        .flatten()
        .for_each(|(address, account_diff)| {
            match merged_state_diffs.entry(address) {
                Entry::Vacant(entry) => {
                    entry.insert(account_diff);
                }
                Entry::Occupied(_) => {
                    // Do nothing if the key already exists
                    // we only care abt the starting state
                }
            }
        });

    Some(merged_state_diffs)
}

And this: In: bot/src/simulate/make_sandwich.rs

        let state = utils::state_diff::get_from_txs(
            &ws_provider,
            &victim_txs,
            BlockNumber::Number(U64::from(fork_block_num)),
        )
        .await
        .unwrap();

We think that

let block_traces = match client.trace_call_many(req, Some(block_num)).await {
        Ok(x) => x,
        Err(_) => {
            // should throw error here but guess None also works :<
            return None;
        }
    };

Is returning ERR None, and this is the failure cause, but we don't know exactly was happening. Any help is appreciated

e7172 commented 1 year ago

Solved, it's was a problem with ws_provider node!

luncht1me commented 1 year ago

Solved, it's was a problem with ws_provider node!

Which version of Erigon did you install to get things working properly? I'm slowly cycling through different commits to get this thing running.

Did you use internal consensus layer or external like prysm?

e7172 commented 1 year ago

Solved, it's was a problem with ws_provider node!

Which version of Erigon did you install to get things working properly? I'm slowly cycling through different commits to get this thing running.

Did you use internal consensus layer or external like prysm?

I switch to use alchemy and quicknode, already have a working version but Im stuck deploying the huff contract. May we can colab in a priv fork?

Klugekluge67 commented 1 year ago

e7172, don't you have rate limit issue with RPC providers like Alchemy or QN (429 error) in the free version? How did you cope with this to have a decent daily rate limit for the RPC websocket subscribed to the mempools? I have deployed huff contract both in testnet and mainnet -> smashingsnails@gmail.com

praveenbm5 commented 1 year ago

I have everythig running along with an Erigon Archive node...

I even deployed the HUFF contract to an efficient address as described in the README.

My problem is that the bot is not taking any trades. Even the tests are not working as shown below. I mean it says not sandwichable for every test which I believe is not the expected output.

cargo test --release -- --nocapture | tee test.log                                                                                                         
   Compiling rusty-sando v0.1.0 (/home/ubuntu/projects/rusty-sando/bot)                                                                                                                                   
    Finished release [optimized + debuginfo] target(s) in 1m 32s                                                                                                                                          
     Running unittests src/lib.rs (target/release/deps/rusty_sando-859cc9e544bb90af)                                                                                                                      

running 8 tests                                                                                                                                                                                           
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 163.471889ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv2_metamask_swap_router ... ok                                                                                                                                    
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 244.208291ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv2_multi_two ... ok                                                                                                                                               
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 461.871991ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv2_kyber_swap ... ok                                                                                                                                              
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 176.305346ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv2_multi_with_three_expect_one_reverts ... ok                                                                                                                     
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 125.464375ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv2_non_sandwichable ... ok                                                                                                                                        
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 128.549949ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv2_sushi_router ... ok                                                                                                                                            
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 131.032598ms                                                                                                                                                                         
test simulate::make_sandwich::test::sandv3_uniswap_universal_router_two ... ok                                                                                                                            
Optimal amount in: 0                                                                                                                                                                                      
not sandwichable                                                                                                                                                                                          
total_duration took: 270.94794ms                                                                                                                                                                          
test simulate::make_sandwich::test::sandv3_uniswap_universal_router_one ... ok                                                                                                                            

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.87s                                                                                                             

     Running unittests src/main.rs (target/release/deps/rusty_sando-464013e871c95dd8)                                                                                                                     

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests rusty-sando

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
SadeRespector commented 1 year ago

My problem is that the bot is not taking any trades. Even the tests are not working as shown below. I mean it says not sandwichable for every test which I believe is not the expected output.

I'm seeing the same thing, but I see the issue is closed now, did you resolve this? and if so how?

praveenbm5 commented 1 year ago

check out #29 for some pointers on this issue

SadeRespector commented 1 year ago

check out #29 for some pointers on this issue

I'm testing the bot, not the contract, my forge tests already pass.

praveenbm5 commented 1 year ago

check out #29 for some pointers on this issue

I'm testing the bot, not the contract, my forge tests already pass.

How did you get the contracts/tests to pass?

What modifications did you make?

Are you using your own Erigon node for ws_privider or some service like chainstack?

SadeRespector commented 1 year ago

check out #29 for some pointers on this issue

I'm testing the bot, not the contract, my forge tests already pass.

How did you get the contracts/tests to pass?

What modifications did you make?

Are you using your own Erigon node for ws_privider or some service like chainstack?

im assuming english isn't your first language or you are confused, I have the same issue of you that optimal in returns 0 and not sandwichable, the forge tests are not my issue.

praveenbm5 commented 1 year ago

i am assuming you cannot read properly.

How did you get the contracts/tests to pass?

I was specifically asking about `contracts/tests' or forge tests!

I had to skip HuffDeployer and directly refernce a deployed sandwich contract to get the tests to pass.

SadeRespector commented 1 year ago

i am assuming you cannot read properly.

How did you get the contracts/tests to pass?

I was specifically asking about `contracts/tests' or forge tests!

I had to skip HuffDeployer and directly refernce a deployed sandwich contract to get the tests to pass.

You specifically sate above you're having the issue when running the cargo tests that your optimal in is 0. that is what im refering too, because YOU posted about it. i am asking bout THOSE tests NOT the forge tests

SadeRespector commented 1 year ago

"praveenbm5 commented last week • I have everythig running along with an Erigon Archive node...

I even deployed the HUFF contract to an efficient address as described in the README.

My problem is that the bot is not taking any trades. Even the tests are not working as shown below. I mean it says not sandwichable for every test which I believe is not the expected output.

cargo test --release -- --nocapture | tee test.log
Compiling rusty-sando v0.1.0 (/home/ubuntu/projects/rusty-sando/bot)
Finished release [optimized + debuginfo] target(s) in 1m 32s
Running unittests src/lib.rs (target/release/deps/rusty_sando-859cc9e544bb90af)

running 8 tests
Optimal amount in: 0
not sandwichable
total_duration took: 163.471889ms
test simulate::make_sandwich::test::sandv2_metamask_swap_router ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 244.208291ms
test simulate::make_sandwich::test::sandv2_multi_two ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 461.871991ms
test simulate::make_sandwich::test::sandv2_kyber_swap ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 176.305346ms
test simulate::make_sandwich::test::sandv2_multi_with_three_expect_one_reverts ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 125.464375ms
test simulate::make_sandwich::test::sandv2_non_sandwichable ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 128.549949ms
test simulate::make_sandwich::test::sandv2_sushi_router ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 131.032598ms
test simulate::make_sandwich::test::sandv3_uniswap_universal_router_two ... ok
Optimal amount in: 0
not sandwichable
total_duration took: 270.94794ms
test simulate::make_sandwich::test::sandv3_uniswap_universal_router_one ... ok

test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.87s

 Running unittests src/main.rs (target/release/deps/rusty_sando-464013e871c95dd8)                                                                                                                     

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Doc-tests rusty-sando

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s"

you posted this im asking about the cargo tests

praveenbm5 commented 1 year ago

Buddy... I am trying to understand how you got your forge tests (contracts/tests) to pass as this could give clues about why bot/tests are failing.

When I posted about cargo tests failing and later referenced an issue that talks about modifications needed to get forge tests to pass, you said you already got forge tests to pass!

So was curious to understand what you had to do to get forge tests to pass.

bot/tests are still failing for me and I am trying to check where they are going wrong!

SadeRespector commented 1 year ago

Buddy... I am trying to understand how you got your forge tests (contracts/tests) to pass as this could give clues about why bot/tests are failing.

When I posted about cargo tests failing and later referenced an issue that talks about modifications needed to get forge tests to pass, you said you already got forge tests to pass!

So was curious to understand what you had to do to get forge tests to pass.

bot/tests are still failing for me and I am trying to check where they are going wrong!

the forge tests and cargo tests are unrelated

praveenbm5 commented 1 year ago

Both tests use the same contracts. So the problems could potentially be related.

But, everyone is free to have their own opinions! All the best!