mev-inspect-rs
mev-inspect-rs copied to clipboard
feat: revised model, detection schemes and more
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
Inspectionstrcut is replaced byTransactionData, which is a complete representation of a transaction with internal calls and all events. - introduce the
DefiProtocoltrait that essential serves as the oldInspectortrait 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 newTransactionData, to make this process a bit more ergonomic, theInternalCallwould need to be separated from the parentTransactionData. ) decode_call_actionhas access to the corresponding events of the call and can decode those using theethers-rsabigenevents. If a decodedActionreferences logs, they are marked and filtered out for upcoming protocols.- Introduced the
ReduceTxtrait which is the same as theReducetrait but now forTransactionData - this has implications for how the order of the (formerly) Inspector and Reducer should be configured for the BatchInspector:
- The
ERC20DefiProtocolshould inspect last, because it should only pick upTransferevents that are not part of anyDefiProtocolinspections that are executed before. - The
LiquidationReducershould run after theTradeRecuder, which bundles alls the various swaps.
- The
- 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 inspection of a transaction is now performed in two steps. First, the internal calls are classified (
- The
MevDBclient can now also store all, none, or only those events+calls used bydecode_call_actionin the database - Included up and down SQL migrations
- Updated all the tests
- Also I've added some (probably poor) initial sandwich detection schemes