Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: revised model, detection schemes and more #59

Open
wants to merge 58 commits into
base: master
Choose a base branch
from

Conversation

mattsse
Copy link
Contributor

@mattsse mattsse commented May 31, 2021

Motivation

This is a big one -.-
First of all, I don't expect everything to be included at once, or even at all. I rather chalk this up to personal research of the various protocols and MEV in general. If some parts of it are useful, I will gladly split it up and submit it separately or revise portions of it as well.

Solution

what I have changed:

  • The Inspection strcut is replaced by TransactionData, which is a complete representation of a transaction with internal calls and all events.
  • introduce the DefiProtocol trait that essential serves as the old Inspector trait and more.
    • The inspection of a transaction is now performed in two steps. First, the internal calls are classified (DefiProtocol::classify) in order, based on the call input. Then an attempt is made to decode the action of the call (DefiProtocol::decode_call_action). (perhaps this is a bit unintuitive, especially because both only take references and not mut, that's due to the design of the new TransactionData, to make this process a bit more ergonomic, the InternalCall would need to be separated from the parent TransactionData. )
    • decode_call_action has access to the corresponding events of the call and can decode those using the ethers-rs abigen events. If a decoded Action references logs, they are marked and filtered out for upcoming protocols.
    • Introduced the ReduceTx trait which is the same as the Reduce trait but now for TransactionData
    • this has implications for how the order of the (formerly) Inspector and Reducer should be configured for the BatchInspector:
      • The ERC20 DefiProtocol should inspect last, because it should only pick up Transfer events that are not part of any DefiProtocol inspections that are executed before.
      • The LiquidationReducer should run after the TradeRecuder, which bundles alls the various swaps.
    • Note: the biggest drawback of this approach is that it does not work reliably for reverted tx's, which may or may not be critical.
  • The MevDB client can now also store all, none, or only those events+calls used by decode_call_action in the database
  • Included up and down SQL migrations
  • Updated all the tests
  • Also I've added some (probably poor) initial sandwich detection schemes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant