NERD ALERT: The Upgraded Algorithm of How EigenPhi Identifies MEV
You might wanna use this to write your own stuff.
As promised, we’d like to share the revamped version of our MEV recognizing algorithm. It’s another move from EigenPhi to benefit the Decentralized Finance (DeFi) community. In the emerging world of DeFi, collaboration and open innovation are key drivers of progress. We hope this will help to increase the security and reliability of smart contracts and blockchain-based applications, which is critical in an environment where trust is essential.
Let’s go!
How EigenPhi Identifies MEV
EigenPhi analyzes three types of MEV, namely Arbitrage, Sandwich, and Liquidation, which aim to examine transaction structures on the ETH and BSC chains.
EigenPhi assists users in comprehending how MEV strategies function regarding asset transfers.
EigenPhi demonstrates how searchers can leverage arbitrages to enhance market productivity and promote market efficiency.
EigenPhi presents the entire Arbitrage, Sandwich, and Liquidation processes through Token Flow charts, increasing community awareness and promoting responsible trading practices.
In summary, by providing users with a better understanding of market dynamics and exposing unethical practices, EigenPhi contributes to a more transparent and productive DeFi ecosystem.
Recognizing Atomic Arbitrage MEV
Since transactions can be highly complex and involve infinite unknown patterns, relying solely on specific transaction pattern matching is inadequate to identify new MEV patterns. To detect Arbitrage in transactions, we need a universal abstraction for transactions.
To achieve this, we have established the following principles for recognition.
We define a transaction as a collection of asset transfers.
Then, we evaluate the outcomes of these transfers using a set of rules to determine if an MEV has occurred.
We break down a transaction into Transfers and Trades.
Our algorithm merges Transfers to form a Transfer Table.
Next, we use the Transfer Table to merge the rows with the same address and generate a Combined Transfer Table.
Our rule of thumb is that if the token balance of the nearest point to the "from" or "to" address within a strongly connected component is positive, we regard this transaction as Arbitrage.
To help you better understand it, next, we will present a detailed process and an example to illustrate our algorithm based on the Token Flow graph generated in our EigenTx tool.
Under The Hood
Directed Graph and Strongly Connected Components
A Directed Graph is a type of graph in which edges have a direction or orientation assigned to them. Each edge connects a source node to a destination node, indicating the direction of the relationship between the two nodes. Below is an example.
Strongly Connected Components (SCC) is a concept in graph theory that refers to a group of vertices in a directed graph. Every vertex in the graph is reachable from every other vertex in the same group. In other words, an SCC is a subgraph of a directed graph in which every vertex is reachable from every other point within the same subgraph. For example, the part of the diagram above beyond point E forms an SCC, as shown below.
Processes for Arbitrage Identification:
Parse the transfers in the transaction, including transfers using ERC20, ERC721, and internal transactions;
Draw a directed graph based on the transfers;
Use an algorithm to identify the strongly connected components in the graph. A graph is strongly connected if every vertex can be reached from every other vertex;
Find the closest point to the "from" or "to" address of the transaction in the above strongly connected components. The "distance" metric is the number of nodes on the shortest path in the strongly connected component. When the "from" or "to" address is already in the graph, the closest point is the "from" or "to" address itself;
Calculate the token profit and loss for this closest point in the strongly connected component;
If the token profit and loss for this closest point are positive, we identify this transaction as an Arbitrage.
A Typical Arbitrage Example
A typical Arbitrage example here involves 3 tokens and 3 liquidity pools identified by EigenPhi:
We use the six steps mentioned earlier to determine whether a transaction is an Arbitrage:
Steps 1 & 2: Parse the transfers in the transaction and draw a directed graph based on the transfers.
Step 3: Identify the strongly connected components in the graph and create a combined transfer table based on it.
The result is that the original graph is the strongly connected components.
Two table below are the transfers list and TransferTable.
Step 4: Find the closest point to the "from" or "to" Address of the transaction in the above strongly connected components.
In view that the "to" address is already in the graph, the closest point is the "to" address itself.
Steps 5 & 6: Calculate the profit of the point (Address) in Step 4, and determine whether it is positive.
(77,406.53 - 76,860.06) USDC + (77,666.66 - 77,666.66) USDT > 0
Therefore, we identify this transaction as an Arbitrage.
What About Sandwich MEV?
Cross-transaction structural analysis is an extension of the above intra-transaction analysis approach. Here is the process.
Analyze all the trades and liquidity additions in a given block.
Use the trades identified in step one to search for sandwich pair trades within the block: these are trades in which the from address is the same, they occur in the same liquidity pool, and the trade direction is opposite.
Once a sandwich trade has been identified, locate the victim transaction between the two sandwich trades: this transaction must have an address different from that of the attacker, occur in the same liquidity pool, and have a trade direction that is the same as the frontrun transaction.
If a complete set of frontrun, victim, and backrun transactions is identified, we deem the trade to be a sandwich trade.
You can click this link to find an example.
All right. That’s pretty much it. Hope this helps! And please feel free to leave your comment below.
Follow us via these to dig more hidden wisdom of DeFi: