Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Sandwich profit amount inflated in some cases #283

Open
Dire-0x opened this issue Feb 25, 2022 · 4 comments
Open

Sandwich profit amount inflated in some cases #283

Dire-0x opened this issue Feb 25, 2022 · 4 comments
Labels
dune impacts dune integration

Comments

@Dire-0x
Copy link
Contributor

Dire-0x commented Feb 25, 2022

I have found that the sandwich.profit_amount in some cases is very inflated... I'll give an example (the amounts below are made up but I have seen many cases of this happening).

frontrun: 1,000,000 USDC -> 100 ETH
backrun: 300 ETH -> 3,200,000 USDC

mev-inspect calculates the profit as 3,200,000 - 1,000,000 USDC

we should calculate the profit pro rata, like this

profit = 100 * (3,200,000 / 300) - 1,000,000

profit should be $66k but is currently calculated as $2.2m

Here is an example case detected by mev-inspect

frontrun: https://etherscan.io/tx/0x59211262bbc5b8260d4d7ea6311ac81d358a09a99a7422f9a27e3b3fbe92b549
backrun: https://etherscan.io/tx/0x87fda6ee1f2c74e106aab959beca197a8749f988c692aedf10c8499ad5805a81

@pmcgoohan
Copy link

This is good. I propose a more conservative version which works for imbalances in both directions (overweight front or back runs).

profitFrontrun = (frontOut * (backOut / backIn) - frontIn)
profitBackrun = (backOut - (backIn * (frontIn / frontOut)))
sandwichProfit = min by abs {profitFrontrun, profitBackrun}

@tutacrypto
Copy link

Hey @Dire-0x @pmcgoohan, what's your progress on this?

I've had another issue with profit calculation from sandwiches. In this case I get a negative profit (loss), where the transaction looks like it should be positive. Curious to here your thoughts.

Screenshot:
Capture d’écran 2022-05-04 à 14 59 32

Frontrun: https://etherscan.io/tx/0x54998a9e51516e5d5979f2a3ea76adb2d609cdeb7c745a01270bf5a03d2cc56a
backrun: https://etherscan.io/tx/0x9d7b0757c6b05751d6141464d4ed7f27499a83445fa17c5e25799675a1cbbeab

You can find the sandwich with this query:

select *
from `flashbots`.`sandwiches`
where block_number = 14659109

@bryanzk
Copy link

bryanzk commented May 17, 2022

@tutacrypto You can check if our calculation was correct here, which the profit is 0. 215237 WETH plus over 5k BLIB.
https://eigenphi.io/ethereum/tx/0xef3b1a72096dd03ccdd7acf8baed8c16e8cc039d1d37fd39a8501d0369f577c0

Hey @Dire-0x @pmcgoohan, what's your progress on this?

I've had another issue with profit calculation from sandwiches. In this case I get a negative profit (loss), where the transaction looks like it should be positive. Curious to here your thoughts.

Screenshot: Capture d’écran 2022-05-04 à 14 59 32

Frontrun: https://etherscan.io/tx/0x54998a9e51516e5d5979f2a3ea76adb2d609cdeb7c745a01270bf5a03d2cc56a backrun: https://etherscan.io/tx/0x9d7b0757c6b05751d6141464d4ed7f27499a83445fa17c5e25799675a1cbbeab

You can find the sandwich with this query:

select *
from `flashbots`.`sandwiches`
where block_number = 14659109

@tutacrypto
Copy link

tutacrypto commented May 23, 2022

Oh nice tool, thanks for sharing @bryanzk
From this link, my computation looks correct ( a ~0.21 wETH profit) and the data on Dune incorrect.

Any news on making the PR with your model @pmcgoohan?

@gheise gheise added the dune impacts dune integration label Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dune impacts dune integration
Projects
None yet
Development

No branches or pull requests

5 participants