mev-inspect-rs icon indicating copy to clipboard operation
mev-inspect-rs copied to clipboard

feat: revised model, detection schemes and more

Open mattsse opened this issue 4 years ago • 0 comments

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

mattsse avatar May 31 '21 17:05 mattsse