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-rsabigen 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 ERC20DefiProtocol 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
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:
Inspection
strcut is replaced byTransactionData
, which is a complete representation of a transaction with internal calls and all events.DefiProtocol
trait that essential serves as the oldInspector
trait and more.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, theInternalCall
would need to be separated from the parentTransactionData
. )decode_call_action
has access to the corresponding events of the call and can decode those using theethers-rs
abigen
events. If a decodedAction
references logs, they are marked and filtered out for upcoming protocols.ReduceTx
trait which is the same as theReduce
trait but now forTransactionData
ERC20
DefiProtocol
should inspect last, because it should only pick upTransfer
events that are not part of anyDefiProtocol
inspections that are executed before.LiquidationReducer
should run after theTradeRecuder
, which bundles alls the various swaps.MevDB
client can now also store all, none, or only those events+calls used bydecode_call_action
in the database